Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon
Labs

Using Ansible to Get Clients to a Specific State

Often you'll find yourself wanting to get a group of servers set up from scratch rather than running individual configuration commands. Often it can seem like a daunting task to write a single playbook to handle a chain of tasks, switching host groups, calling multiple modules, and more.This lab will give you the opportunity to practice writing a playbook that will run all of that at once. *This course is not approved or sponsored by Red Hat.*

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 45m
Published
Clock icon Oct 18, 2019

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Install the "linuxacademy-backup-software" Package throughout Our Environment

    1. This section of our playbook should look like:
    ---
    - name: Install backup software
      hosts: all
      become: yes
      tasks:
       - name:  yum command
         yum:
          name: linuxacademy-backup-software
          state: present
         ignore_errors: yes    
    
  2. Challenge

    Install httpd on the webserver Group

    1. The next section of the playbook should look like this:
    - name: Install httpd
      hosts: webservers
      become: yes
      tasks:
       - name: httpd install
         yum:
          name: httpd
          state: present
       - name: Service management for httpd
         service:
          name: httpd
          state: started
          enabled: yes
    
  3. Challenge

    Start and Enable the httpd Service on the webserver Group

    1. Continuing from the last task, the next section should look like this:
       - name: Service management for httpd
         service:
          name: httpd
          state: started
          enabled: yes
    
  4. Challenge

    Create a dba User Account on the dbserver Group

    1. This portion of our playbook should look like this:
    - name: DB server management
      hosts: dbservers
      become: yes
      tasks:
       - name: Add user
         user:
          name: dba
          state: present
    
  5. Challenge

    Copy /root/DBAstuff.txt to the New User's Home Directory

    1. Continuing along from the last task, this portion of our playbook should look like this:
       - name: Copy DB user data
         copy:
          src: /root/DBAstuff.txt
          dest: /home/dba/DBAstuff.txt
          owner: dba
          group: dba
          mode: 0600
    
  6. Challenge

    Create index.html in /var/www/html on the Web Server

    1. This portion of our playbook should look like this:
    - name: Set up index.html on webservers
      hosts: webservers
      become: yes
      tasks:
       - name: Create and populate index.html
         lineinfile:
          path: /var/www/html/index.html
          line: Waiting for content.
          create: yes
          owner: apache
          group: apache
          mode: 0644
    
  7. Challenge

    Install Git on the webserver and dbserver Groups, If It Is Not Already Installed

    1. This next portion of our playbook should look like this:
    - name: Enable devs to easily populate content
      hosts: webservers:dbservers
      become: yes
      tasks:
       - name: Install git
         yum:
          name: git
          state: present
    
  8. Challenge

    Create Red Hat Server-Specific Files

    1. This last portion of our playbook should look like this:
    - name: Red Hat specific configuration
      hosts: all
      become: yes
      tasks:
       - name: Populate file with IP addresses
         lineinfile:
          path: /root/addresses
          line: "{{ ansible_facts['all_ipv4_addresses'] }}"
          create: yes
         when: ansible_facts['os_family'] == 'RedHat'
    
  9. Challenge

    Running the Playbook

    1. To set our playbook in motion, run this:
    ansible-playbook state.yml
    

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans