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.*
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- 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
- This section of our playbook should look like:
- 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
- The next section of the playbook should look like this:
- 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
- Continuing from the last task, the next section should look like this:
- 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
- This portion of our playbook should look like this:
- 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
- Continuing along from the last task, this portion of our playbook should look like this:
- 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
- This portion of our playbook should look like this:
- 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
- This next portion of our playbook should look like this:
- 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'
- This last portion of our playbook should look like this:
- Running the Playbook
- To set our playbook in motion, run this:
ansible-playbook state.yml
- To set our playbook in motion, run this: