- Lab
- A Cloud Guru
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.*
Path Info
Table of Contents
-
Challenge
Install the "linuxacademy-backup-software" Package throughout Our Environment
- 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
-
Challenge
Install httpd on the webserver Group
- 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
-
Challenge
Start and Enable the httpd Service on the webserver Group
- Continuing from the last task, the next section should look like this:
- name: Service management for httpd service: name: httpd state: started enabled: yes
-
Challenge
Create a dba User Account on the dbserver Group
- 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
-
Challenge
Copy /root/DBAstuff.txt to the New User's Home Directory
- 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
-
Challenge
Create index.html in /var/www/html on the Web Server
- 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
-
Challenge
Install Git on the webserver and dbserver Groups, If It Is Not Already Installed
- 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
-
Challenge
Create Red Hat Server-Specific Files
- 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'
-
Challenge
Running the Playbook
- To set our playbook in motion, run this:
ansible-playbook state.yml
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.