Variables are another thing that makes Ansible powerful. By being able to write generic commands, with decision trees based on variables, we can automate almost anything. This lab will walk through a couple of things we can do with variables to help burn in the concept.
*This course is not approved or sponsored by Red Hat.*
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Write a Playbook That Removes `tcpdump` When a Server’s Name Does Not Contain `admin`
Your playbook should look something like this:
--- # Variables playbook - name: This playbook will remove tcpdump (if installed) from servers without admin in their hostnames hosts: all become: yes tasks: - name: Remove tcpdump from all but admin servers yum: name: tcpdump state: absent when: "'admin' not in inventory_hostname"
- Modify That Playbook to Install Git on RedHat Servers
Your additional lines should look something like this:
- name: Make sure git is installed only on Red Hat servers yum: name: git state: present when: ansible_facts['os_family'] == 'RedHat'