Today's challenges come straight from Adam! These are goals he recommended, so uh... blame him!
ADAM HAS CHARGED YOU TO BE ABLE TO DO THE FOLLOWING:
- Iterating through a loop in the YAML inventory (firewall whitelist with multiple services – ssh, http, https)
- Copying a file from the ansible repo to the remote host
- Copying an unmodified file as-is (test.txt)
- Copying a file and modifying it with a jinja2 template and a variable from the inventory (ntp server)
all:
hosts:
children:
planetexpress:
hosts:
bender:
ansible_host: 10.10.2.3
ansible_user: bender
fry:
ansible_host: 10.10.2.4
ansible_user: fry
zoidberg:
ansible_host: 10.10.2.5
ansible_user: zoidberg
farnsworth:
ansible_host: 10.10.2.6
ansible_user: farnsworth
ansible_python_interpreter: /usr/bin/python
vars:
ansible_python_interpreter: /usr/bin/python3
ansible_ssh_pass: alta3
-
Create a new inventory file using the YAML above.
-
Add variable
firewall_whitelist
shown below as a group var to the inventory above.firewall_whitelist: - ssh - http - https
-
Create a short playbook that uses the above inventory. Here's a little bit to get you started:
- name: looping group vars hosts: planetexpress tasks: - name: permit traffic in default zone for https service ansible.posix.firewalld: zone: public service: https permanent: yes state: enabled become: yes
-
Edit this playbook so that we loop across the
firewall_whitelist
group var, feeding each firewall to theservice
parameter one at a time! Read more about the firewalld module here!
Take your pick of any of the following for part 2!
- Copy a file from
bchd
(doesn't matter what file) to all hosts inplanetexpress
(doesn't matter where)
-
Download the following template:
wget https://raw.githubusercontent.com/csfeeser/ansible_essentials/main/data/challenge_template.j2
-
Using the template module, create a completed version of
challenge_template.j2
on allplanetexpress
hosts.
-
The GitHub repo https://github.com/csfeeser/mycode2 has three files in it named
moveme1.txt
,moveme2.txt
, andmoveme3.txt
. Clone this repo and its contents to the/tmp
directories of allplanetexpress
hosts. -
Consider using the ansible.builtin.git module for this one!