One place for hosting & domains

      Install

      Install GitLab on Ubuntu 18.04


      Updated by Linode

      Contributed by

      Linode

      GitLab is a complete solution for all aspects of your software development life-cycle. At its core, GitLab serves as your centralized Git repository. It also features built-in tools that represent every task in your development workflow, from planning to testing to releasing. You can host your own GitLab instance on a Linode, instead of using third-party hosting. Self-hosting your software development with GitLab offers total control of your codebase while providing an easy to use interface for team members. GitLab is the most popular self-hosted Git repository, so you’ll benefit from a robust set of integrated tools and an active community.

      This guide will walk you through the steps to install GitLab on an 8GB Linode running Ubuntu 18.04. This installation can support up to 100 users.

      System Requirements

      Before installing GitLab you should consider how many users will collaborate on your self-hosted instance, the size of the repositories you will store, and the recommended minimum system requirements. This criteria will will effect the needed storage, CPU, and memory. This guide will use an 8GB Linode plan to fulfill GitLab’s minimum system requirements. The suggested hardware is as follows:

      • Storage The required storage depends on the size of the repositories you will store in GitLab. You should plan to have at least as much free space as all the repositories combined require.
      • CPU: 2 cores is the recommended number and supports up to 500 users. While you can use 1 CPU core to support 100 users, the application may run slower because all workers and background jobs will run on the same core.
      • Memory: 8 GB to support up to 100 users.

      Before You Begin

      1. Familiarize yourself with our Getting Started guide and complete the steps for setting your Linode’s hostname and timezone.

      2. This guide will use sudo wherever possible. Complete the sections of our Securing Your Server to create a standard user account, harden SSH access and remove unnecessary network services.

      3. Add a domain zone, NS record, and A/AAA record for the domain you will use to access your GitLab installation. See the DNS Manager guide for details. If you will access your GitLab instance via your Linode’s IP address, you can skip this step.

      4. Create an SSL Certificate, if you will be using SSL encryption for your domain (this is recommended). Be sure to note the location that Certbot uses to store all generated keys and issued certificates.

      5. Update your system:

        sudo apt-get update && sudo apt-get upgrade
        

      Install GitLab

      1. Install all required dependencies:

        sudo apt-get install -y curl openssh-server ca-certificates
        
      2. Install Postfix to send email notifications:

        sudo apt-get install -y postfix
        

        When prompted, select Internet Site and press Enter. Use your server’s external DNS for mail name and press Enter.

      3. Add the GitLab package repository:

        curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash
        
      4. Install the GitLab package. Replace gitlab.example.com with the domain you will use to access your GitLab installation. The installation will automatically configure and start GitLab.

        sudo EXTERNAL_URL="http://gitlab.example.com" apt-get install gitlab-ee
        
      5. In your browser of choice, navigate to the URL you provided in the previous step. You will be redirected to GitLab’s password reset screen. You should provide a password for the GitLab administrator account.

        GitLab password reset

      6. You will be redirected to the login screen. Enter root as the username and the password you just created to log in.

        GitLab welcome screen

      Configure SSL Encryption

      Note

      If you did not generate an SSL certificate using Certbot prior to the installation of GitLab, you may need to first stop GitLab and then generate the SSL certificate to bypass any errors related to Certbot’s certificate challenge. To stop GitLab run the following command:

        sudo gitlab-ctl stop
      

      Once you are done generating the certificate, restart GitLab with the following command:

        sudo gitlab-ctl start
      
      1. Edit the /etc/gitlab/gitlab.rb to use HTTPS. This is done by modifying the value of external_url to use https instead of http:

        /etc/gitlab/gitlab.rb
        1
        2
        3
        4
        5
        6
        
        ## GitLab URL
        ##! URL on which GitLab will be reachable.
        ##! For more details on configuring external_url see:
        ##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
        external_url 'https://gitlab.example.com'
              
      2. Edit the /etc/gitlab/gitlab.rb file to point to the location of your SSL certificate and key. The path should be the location used by Certbot to store the certificates when they were initially created.

        /etc/gitlab/gitlab.rb
        1
        2
        3
        
        nginx['ssl_certificate'] = "/etc/letsencrypt/live/gitlab.example.com/fullchain.pem"
        nginx['ssl_certificate_key'] = "/etc/letsencrypt/live/gitlab.example.com/privkey.pem"
              
      3. Redirect all HTTP traffic to HTTPS:

        /etc/gitlab/gitlab.rb
        1
        2
        
        nginx['redirect_http_to_https'] = true
              
      4. Issue the following command to enable your new configurations:

        sudo gitlab-ctl reconfigure
        
      5. Navigate to your GitLab instance domain and verify that you are directed to https.

      You are now ready to begin using GitLab as your remote version control system. Refer to GitLab’s official documentation for details on how to get started administering your GitLab instance.

      More Information

      You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

      Find answers, ask questions, and help others.

      This guide is published under a CC BY-ND 4.0 license.



      Source link

      Install GitLab with Docker


      Updated by Linode

      Contributed by

      Linode

      GitLab is a free Git repository management application, like GitHub or Bitbucket, that you can run on your own Linode. This guide will show you how to install GitLab using the official GitLab Docker image.

      The GitLab application has a number of services it depends on, including PostgreSQL, Nginx, and Redis. A major benefit of using Docker to install GitLab is that these dependencies are isolated to a single easy-to-update and self-contained image.

      Before You Begin

      Choose An Appropriately Sized Linode

      GitLab is a resource-intensive application. To get the most out of GitLab, we recommend a Linode with at least 8GB of memory and at least 2 CPU cores. For more information on system requirements, visit the GitLab Hardware Requirements page.

      Note

      This guide was written for and tested with Ubuntu 18.04. You may be able to adapt this guide to other operating systems supported by Docker. When following this guide under another OS, use the Docker installation instructions for that OS.

      Secure your Server

      Review and implement the measures in the How to Secure your Server guide, including creating a limited user account.

      Change your Linode’s Default SSH Port

      One of GitLab’s features is the ability for you to push and fetch code changes to and from your repository over SSH. When installing GitLab, the software will need to bind to port 22, which is the standard port for SSH. Your system’s SSH service already runs on this port by default, so you will receive an error from GitLab if you don’t address this conflict.

      To fix this, you’ll want to change the port that your system’s SSH service listens on. This can be accomplished by editing your Linode’s /etc/ssh/sshd_config file and changing the Port assignment. The example snippet below changes the port from 22 to port 26:

      /etc/ssh/sshd_config

      When editing the file, you may also need to uncomment the Port line by removing the # character from the start of the line, if one is present. After updating this file and saving the change, restart the SSH service:

      sudo systemctl restart sshd
      

      Close your current SSH session and create a new one, making sure to specify the new port. You can do this by supplying the -p flag:

      ssh your_limited_user@192.0.2.2 -p 26
      

      (Optional) Update your DNS Records

      Assign a domain or subdomain to your GitLab server. This step is optional, as you can always access GitLab via your server’s IP address. However, using a domain is necessary if you would like to take advantage of GitLab’s built in SSL support, which uses Let’s Encrypt to issue certificates. This guide’s examples will use gitlab.example.com.

      It takes some time for DNS changes to propagate through the internet, so it’s suggested that you do this before you set up GitLab. There are several options for updating your DNS records:

      • If you already use Linode’s name servers, or if you would like to use them for your domain, review the DNS Manager guide. You will need to set up an A record which is assigned your Linode’s IP address.

      • If you use a different DNS provider, review that provider’s documentation for setting up a new A record.


        Updating DNS records at common nameserver authorities

        The following support documents describe how to update DNS records at common nameserver authorities:

      You can test to see if your DNS changes have propagated with the dig command:

      dig +short gitlab.example.com
      
        
      192.0.2.2
      
      

      Once your changes have propagated, you can move forward with the installation.

      Install Docker

      You must have Docker installed on your Linode to continue.

      These steps install Docker Community Edition (CE) using the official Ubuntu repositories. To install on another distribution, see the official installation page.

      1. Remove any older installations of Docker that may be on your system:

        sudo apt remove docker docker-engine docker.io
        
      2. Make sure you have the necessary packages to allow the use of Docker’s repository:

        sudo apt install apt-transport-https ca-certificates curl software-properties-common
        
      3. Add Docker’s GPG key:

        curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
        
      4. Verify the fingerprint of the GPG key:

        sudo apt-key fingerprint 0EBFCD88
        

        You should see output similar to the following:

          
        pub   4096R/0EBFCD88 2017-02-22
                Key fingerprint = 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
        uid                  Docker Release (CE deb) 
        sub   4096R/F273FCD8 2017-02-22
        
        
      5. Add the stable Docker repository:

        sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
        
      6. Update your package index and install Docker CE:

        sudo apt update
        sudo apt install docker-ce
        
      7. Add your limited Linux user account to the docker group:

        sudo usermod -aG docker $USER
        

        Note

        After entering the usermod command, you will need to close your SSH session and open a new one for this change to take effect.

      8. Check that the installation was successful by running the built-in “Hello World” program:

        docker run hello-world
        

      Install the GitLab EE Image

      After installing Docker, download the latest GitLab Enterprise Edition Docker image from DockerHub. This image contains everything GitLab needs in order to run: PostgreSQL, Nginx, Redis, etc. To download the image, run the following pull command:

      sudo docker pull gitlab/gitlab-ee:latest
      


      Community Edition or Enterprise Edition?

      The GitLab Enterprise Edition software does not actually require you to have a license to use it. If you do not supply a license after installation, it will automatically show you the GitLab Community Edition feature set instead.

      If you’d like, you can instead opt to download GitLab Community Edition. This will offer the same features as an unlicensed Enterprise Edition installation. The key difference between these software packages is that the features of the EE installation can be upgraded at any time by entering a license.

      The primary reason someone might download the Community Edition is if they prefer to only download open source software. For more information on GitLab’s licensing, review the GitLab article on this subject. To download the GitLab CE Docker image, run this command:

      sudo docker pull gitlab/gitlab-ce:latest
      

      It may take a few minutes to download the image. When the download is complete, you can view a list of all installed Docker images with the images command:

      sudo docker images
      

      Configure and Run GitLab

      In order to configure and run the GitLab container, you need to provide a few options at runtime.

      1. Consider the following command, a version of which you will use to start the GitLab container:

        sudo docker run --detach 
          --hostname gitlab.example.com 
          --publish 443:443 --publish 80:80 --publish 22:22 
          --name gitlab-linode 
          --restart always 
          --volume /srv/gitlab/config:/etc/gitlab 
          --volume /srv/gitlab/logs:/var/log/gitlab 
          --volume /srv/gitlab/data:/var/opt/gitlab 
          --env GITLAB_OMNIBUS_CONFIG="external_url 'https://gitlab.example.com/';" 
          gitlab/gitlab-ee:latest
        


        Descriptions for each option

        --detach runs the Docker container as a background process, as opposed to running it in the foreground.

        --hostname defines the container’s internal hostname.

        --publish tells the container to publish ports, or ranges of ports, to the host. Because GitLab accepts connections on the HTTP (80), HTTPS (443), and SSH (22) ports, this option is declared three times. If you wanted to access GitLab from a non-standard port on your host, you would provide the host port first, and the container port second after the semi-colon. For instance if you wanted to access GitLab SSH on port 3333, you would write --publish 3333:22.

        --name allows you to apply a label to your container, for use when referencing the container within a Docker network.

        --restart specifies a restart policy for the container. Here it is set to always, meaning that the container, if exited, will automatically be restarted.

        --volume defines the host mounted volumes the container uses to store persistent data. These three volumes store application data, log files, and configuration files. The value to the left of the the semi-colon is the local location, and the value to the right is the container location.

        --env supplies the variable GITLAB_OMNIBUS_CONFIG, which can hold a series of values, separated by a colon, that correspond to the GitLab Omnibus configuration settings. In this case, an external URL is supplied. Some additional settings might include SMTP configuration values so that GitLab can send activity emails.

        As of GitLab 10.7, if you provide an external URL with a HTTPS protocol, GitLab will automatically set up SSL certificates using Let’s Encrypt, and all traffic will be forwarded to HTTPS. For more information about this functionality, read the GitLab SSL Documentation

        As an alternative to specifying the GITLAB_OMNIBUS_CONFIG variable via the --env option, you can edit the GitLab configuration file directly. For more instructions on how to do that, visit the Configure GitLab documentation.

      2. In the above command, replace the values for the --hostname option and for the external_url configuration setting with the domain or subdomain for your GitLab site. If you did not set up DNS for your site, enter http://your_linode_ip (not https) for the external_url setting. Then, run the command.

        Note

        If you are using the GitLab Community Edition image, replace gitlab/gitlab-ee:latest with gitlab/gitlab-ce:latest

        The container may take a few moments to start. After it starts, you’ll be given a container ID like the following:

          
        1093d89f9a0af8e4c79e0352e57721b09050d07c86c37d601145a856f3ed1502
        
        
      3. It will take an additional few minutes to be able to access GitLab in your browser after the container starts. You can find out more information about the startup process by monitoring the logs:

        sudo docker logs -f gitlab-linode
        

        To exit from the log monitoring process, enter CTRL-C. This will not stop the container from running.

      4. Load the GitLab site in your web browser. If you try to load it too shortly after starting the container, you may see an HTTP 502 error. If this happens, try waiting for a few more minutes and then refresh your page.

      5. The first time you access the site it will prompt you to enter an administrative password. Enter a complex password and record it somewhere safe.

      6. Log in to your GitLab site by entering root as the user along with the password you created in the previous step.

      Create your First Project

      Each repository in GitLab belongs to a project. A project includes: a repository for your files, an issues tracker, a section for merge requests, a wiki, continuous integration and continuous delivery (CI/CD) pipelines, and other features to support your development.

      1. To create your first repository, click Create a project.

        From the welcome screen, click "Create a project"

      2. You will be taken to the New Project page. Enter the project name. You can optionally alter the project’s slug, enter a description, or change the visibility of the project. Once you’re done, click Create project.

        Fill out the required information to make a new project

      3. Once your project has been created, you’ll be provided with an empty project repository:

        An empty project on GitLab

      4. If you didn’t have GitLab create a README.md file during project setup, instructions on how to start using your repository from the command line will be shown.

        Enter those commands on your computer to add a new README.md to your repository and push it back up to your GitLab repository. Change the domain in the git clone command to your site’s domain:

        git clone https://gitlab.example.com/testuser/example-project.git
        cd example-project
        touch README.md  # Or create the file in your editor and enter a project description
        git add README.md
        git commit -m "add README"
        git push -u origin master
        

      Manage the GitLab Container

      To view all of your running containers, you can issue the ps command:

      sudo docker ps
      

      To stop the GitLab container, issue the stop command by supplying the container ID you procured with the ps command, or supply the container name:

      sudo docker stop gitlab-linode
      

      To start a stopped container, issue the start command by supplying the container ID or container name:

      sudo docker start gitlab-linode
      

      Once the container has stopped, you can remove the container using the rm command, again supplying the container ID or container name:

      sudo docker container rm gitlab-linode
      

      Note

      Removing the container will not delete your projects and repositories.

      Upgrading GitLab

      To upgrade GitLab to the newest version, you must stop and remove the container, pull the newest image, and then recreate the container:

      sudo docker stop gitlab-linode
      sudo docker rm gitlab-linode
      sudo docker pull gitlab/gitlab-ee:latest
      
      sudo docker run --detach 
        --hostname gitlab.example.com 
        --publish 443:443 --publish 80:80 --publish 22:22 
        --name gitlab-linode 
        --restart always 
        --volume /srv/gitlab/config:/etc/gitlab 
        --volume /srv/gitlab/logs:/var/log/gitlab 
        --volume /srv/gitlab/data:/var/opt/gitlab 
        --env GITLAB_OMNIBUS_CONFIG="external_url 'https://gitlab.example.com/';" 
        gitlab/gitlab-ee:latest
      

      Remember to provide your own hostname, name, and external URL. If you are using GitLab Community Edition, specify the gitlab/gitlab-ce:latest image instead.

      Next Steps

      GitLab offers many features that are worth taking the time to understand and utilize. Here are a few next steps to take after you’ve completed this guide:

      • Upload an SSH key to your GitLab account so that you can transfer files over SSH.

      • Explore CI/CD pipelines to streamline your development practices.

      • Using your root GitLab account, explore the Admin settings to customize the functionality of GitLab.

      • Review Linode’s Git documentation:

      More Information

      You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

      Find answers, ask questions, and help others.

      This guide is published under a CC BY-ND 4.0 license.



      Source link

      Install and Manage MySQL Databases with Puppet Hiera on Ubuntu 18.04


      Updated by Linode Contributed by Linode

      Puppet is a configuration management system that helps simplify the use and deployment of different types of software, making system administration more reliable and replicable. In this guide, we use Puppet to manage an installation of MySQL, a popular relational database used for applications such as WordPress, Ruby on Rails, and others. Hiera is a method of defining configuration values that Puppet will use to simplify MySQL configuration.

      In this guide, you’ll use Puppet to deploy modules on your server. At the end, you will have MySQL installed, configured, and ready to use for a variety of applications that require a database backend.

      Note

      This guide is written for a non-root user. Commands that require elevated privileges are prefixed with sudo. If you’re not familiar with the sudo command, see the Users and Groups guide.

      Before You Begin

      1. A Linode 1GB plan should be sufficient to run MySQL. Consider using a larger plan if you plan to use MySQL heavily, or for more than just a simple personal website.

      2. Familiarize yourself with our Getting Started guide and complete the steps for setting your Linode’s hostname and timezone.

      3. This guide will use sudo wherever possible. Complete the sections of our Securing Your Server to create a standard user account, harden SSH access and remove unnecessary network services.

      4. Update your system:

        sudo apt-get update && sudo apt-get upgrade
        

      Install and Configure Puppet

      Follow these steps to set up Puppet for single-host, local-only deployment. If you need to configure more than one server or to deploy a Puppet master, follow our multi-server Puppet guide.

      Install the Puppet Package

      1. Install the puppetlabs-release-bionic repository to add the Puppet packages:

        wget https://apt.puppetlabs.com/puppet-release-bionic.deb
        sudo dpkg -i puppet-release-bionic.deb
        
      2. Update the apt package index to make the Puppet Labs repository packages available, then install Puppet. This will install the puppet-agent package, which provides the puppet executable within in a compatible Ruby environment:

        sudo apt update && sudo apt install puppet-agent
        
      3. Confirm the version of Puppet installed:

        puppet --version
        

        At the time of writing, the Puppet version is 6.1.0.

      Install the Puppet MySQL Module

      Puppet Forge is a collection of modules that aid in the installation of different types of software. The MySQL module handles the installation and configuration of MySQL without you needing to manage various configuration files and services by hand.

      1. Install the MySQL module:

        sudo puppet module install puppetlabs-mysql --version 7.0.0
        

        This will install the mysql module into the default path: /etc/puppetlabs/code/environments/production/modules/.

      Puppet MySQL Manifest

      This guide uses a Puppet manifest to provide Puppet with installation and configuration instructions. Alternatively, you can configure a Puppet master.

      While the entirety of a Puppet manifest can contain the desired configuration for a host, values for Puppet classes or types can also be defined in a Hiera configuration file to simplify writing Puppet manifests in most cases. In this example, the mysql::server class parameters will be defined in Hiera, but the class must first be applied to the host.

      To apply the mysql::server class to all hosts by default, create the following Puppet manifest:

      /etc/puppetlabs/code/environments/production/manifests/site.pp
      1
      
      include ::mysql::server

      Note that site.pp is the default manifest file. Without a qualifying node { .. } line, this applies the class to any host applying the manifest. Puppet now knows to apply the mysql::server class, but still needs values for resources like databases, users, and other settings. Configure Hiera to provide these values in the next section.

      Install and Configure Puppet Hiera

      To understand how Hiera works, consider this excerpt from the default hiera.yaml file:

      /etc/puppetlabs/code/environments/production/hiera.yaml
      1
      2
      3
      4
      5
      6
      7
      
      ---
      version: 5
      hierarchy:
        - name: "Per-node data"
          path: "nodes/%{::trusted.certname}.yaml"
        - name: "Common data"
          path: "common.yaml"

      This Hiera configuration instructs Puppet to accept variable values from nodes/%{::trusted.certname}.yaml. If your Linode’s hostname is examplehostname, define a file called nodes/examplehostname.yaml). Any variables found in YAML files higher in the hierarchy are preferred, while any variable names that do not exist in those files will fall-through to files lower in the hierarchy (in this example, common.yaml).

      The following configuration will define Puppet variables in common.yaml to inject variables into the mysql::server class.

      Initial Hiera Configuration

      Hiera configuration files are formatted as yaml, with keys defining the Puppet parameters to inject their associated values. To get started, set the MySQL root password. The following example of a Puppet manifest is one way to control this password:

      example.pp
      1
      2
      3
      
      class { '::mysql::server':
        root_password => 'examplepassword',
      }

      We can also define the root password with the following Hiera configuration file. Create the following YAML file and note how the root_password parameter is defined as Hiera yaml:

      /etc/puppetlabs/code/environments/production/data/common.yaml
      1
      
      mysql::server::root_password: examplepassword

      Replace examplepassword with the secure password of your choice. Run Puppet to set up MySQL with default settings and the chosen root password:

      sudo -i puppet apply /etc/puppetlabs/code/environments/production/manifests/site.pp
      

      Puppet will output its progress before completing. To confirm MySQL has been configured properly, run a command:

      mysql -u root -p -e 'select version();'
      

      Enter the password and MySQL returns its version:

      +-------------------------+
      | version()               |
      +-------------------------+
      | 5.7.24-0ubuntu0.18.04.1 |
      +-------------------------+
      

      Define MySQL Resources

      Using Hiera, we can define the rest of the MySQL configuration entirely in yaml. The following steps will create a database and user for use in a WordPress installation.

      1. Create a pre-hashed MySQL password. Replace the password wordpresspassword in this example, and when prompted for a the root MySQL password, use the first root password chosen in the previous section to authenticate. Note the string starting with a * that the command returns for Step 2:

        mysql -u root -p -NBe 'select password("wordpresspassword")'
        *E62D3F829F44A91CC231C76347712772B3B9DABC
        
      2. With the MySQL password hash ready, we can define Hiera values. The following YAML defines parameters to create a database called wordpress and a user named wpuser that has permission to connect from localhost. The YAML also defines a GRANT allowing wpuser to operate on the wordpress database with ALL permissions:

        /etc/puppetlabs/code/environments/production/data/common.yaml
         1
         2
         3
         4
         5
         6
         7
         8
         9
        10
        11
        12
        13
        14
        
        mysql::server::root_password: examplepassword
        mysql::server::databases:
          wordpress:
            ensure: present
        mysql::server::users:
          wpuser@localhost:
            ensure: present
            password_hash: '*E62D3F829F44A91CC231C76347712772B3B9DABC'
        mysql::server::grants:
          wpuser@localhost/wordpress.*:
            ensure: present
            privileges: ALL
            table: wordpress.*
            user: wpuser@localhost
      3. Re-run Puppet:

        sudo -i puppet apply /etc/puppetlabs/code/environments/production/manifests/site.pp
        
      4. The wpuser should now be able to connect to the wordpress database. To verify, connect to the MySQL daemon as the user wpuser to the wordpress database:

        mysql -u wpuser -p wordpress
        

        After you enter the password for wpuser, exit the MySQL prompt:

        exit
        

      Add Hierarchies for Specific Environments

      Additional configurations can be added that will only be applied to specific environments. For example, backup jobs may only be applied for hosts in a certain region, or specific databases can be created in a particular deployment.

      In the following example, Puppet will configure the MySQL server with one additional database, but only if that server’s distribution is Debian-based.

      1. Modify hiera.yaml to contain the following:

        /etc/puppetlabs/code/environments/production/hiera.yaml
        1
        2
        3
        4
        5
        6
        7
        8
        
        ---
        version: 5
        hierarchy:
          - name: "Per OS Family"
            path: "os/%{facts.os.family}.yaml"
          - name: "Other YAML hierarchy levels"
            paths:
              - "common.yaml"

        This change instructs Hiera to look for Puppet parameters first in "os/%{facts.os.family}.yaml" and then in common.yaml. The first, fact-based element of the hierarchy is dynamic, and dependent upon the host that Puppet and Hiera control. In this Ubuntu-based example, Hiera will look for Debian.yaml in the os folder, while on a distribution such as CentOS, the file RedHat.yaml will automatically be referenced instead.

      2. Create the following YAML file:

        /etc/puppetlabs/code/environments/production/data/os/Debian.yaml
        1
        2
        3
        4
        5
        6
        7
        
        lookup_options:
          mysql::server::databases:
            merge: deep
        
        mysql::server::databases:
          ubuntu-backup:
            ensure: present

        Though similar to the common.yaml file defined in previous steps, this file will add the ubuntu-backup database only on Debian-based hosts (like Ubuntu). In addition, the lookup_options setting ensures that the mysql::server:databases parameter is merged between Debian.yaml and common.yaml so that all databases are managed. Without lookup_options set to deeply merge these hashes, only the most specific hierarchy file will be applied to the host, in this case, Debian.yaml.

        • Alternatively, because our Puppet manifest is short, we can test the same command using the -e flag to apply an inline manifest:

          sudo -i puppet apply -e 'include ::mysql::server'
          
      3. Run Puppet and observe the changes:

        sudo -i puppet apply /etc/puppetlabs/code/environments/production/manifests/site.pp
        
      4. Verify that the new database exists:

        mysql -u root -p -e 'show databases;'
        

        This includes the new ubuntu-backup database:

        +---------------------+
        | Database            |
        +---------------------+
        | information_schema  |
        | mysql               |
        | performance_schema  |
        | sys                 |
        | ubuntu-backup       |
        | wordpress           |
        +---------------------+
        

      Congratulations! You can now control your Puppet configuration via highly configurable Hiera definitions.

      More Information

      You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

      Find answers, ask questions, and help others.

      This guide is published under a CC BY-ND 4.0 license.



      Source link