Ansible has many built in modules, but some are used a lot more than others. In this lab we’re going to reinforce the usage of some of the more common ones, so that they’re easier for you to remember when the time comes.
*This course is not approved or sponsored by Red Hat.*
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Verify Connectivity in the Environment
On the command line run
ansible -m ping all
.- Install httpd
Your playbook,
webservers.yml
should look something like this:--- # Common Modules Playbook # - name: Common Modules Playbook become: yes hosts: webservers tasks: - name: Install httpd on webservers yum: name: httpd state: present
- Start and Enable the httpd Service
In this task all we have to do is add the following to the
webservers.yml
playbook:- name: Start the httpd service service: name: httpd state: started enabled: yes
- Create a dba User Account
Your playbook,
dbserver.yml
, should look similar to this:--- - name: DB server playbook become: yes hosts: dbservers tasks: - name: Add the 'dba' user to the dbservers user: name: dba
- Copy the Required File
You can add to your
dbserver.yml
playbook something similar to the following:- name: Copy required DBA files copy: src: /root/DBAstuff.txt dest: /home/dba/ owner: dba group: dba mode: 0600
- Create /var/www/html/index.html
The final addition to your
webserver.yml
playbook should look similar to:- name: Create index.html file: path: /var/www/html/index.html state: touch
- Clone the Ansible Git Repository into /opt on adminservers
Your admin.yml playbook will look something like this:
--- - name: Use git to clone the Ansible repo hosts: admins become: yes tasks: - name: Install git yum: name: git state: present - name: Use the git module git: repo: https://github.com/ansible/ansible.git dest: /opt