Lab 7 - Variables & Roles Variables¶
Mandatory¶
Host Groups¶
- Edit your existing inventory file
hosts - Create the host_group
weband add your webservers - Create the host_group
dband add your dbserver - Run the ping module to test the new host groups
webanddb
group_vars¶
- Create the
group_varsdirectory in/home/ansible/training - Create
group_vars/all.yml - add the variable
myvarwith the valuevariable for all servers - Run a task (ad-hoc or in playbook) on all servers to print out the variable
myvarwith the Debug Module - Add the variable
myvarwith the valuevariable for web serversonly for thewebgroup - Run a task (ad-hoc or in playbook) on all servers to print out the variable
myvarwith the Debug Module
host_vars¶
- Create the
host_varsdirectory in/home/ansible/training - Create a host variable file for the server
web1.<firstname>.lab - Add the variable
myvarwith the valuehost variable for web1 - Run a task (ad-hoc or in playbook) on all servers to print out the variable
myvarwith the Debug Module
Role Variables & Loops¶
- Extend your
ntprole - Create a
vars/main.ymlfile - Add list variable
ntp_packageswith the itemsntp&ntpdate - Rewrite your
tasks/main.yml - use the new defined variable
ntp_packagesin combination withwith_itemsto install both packages (see Chapter Variables) - Run the playbook
Role Default Variables¶
- Extend your
ntprole - Create a
defaults/main.ymlfile - Add a list of servers to a new variable
ntp_servers(you can use your example from your lab4.yml) - Extend the
tasks/main.ymlwith a debug task to print out the defined list variablentp_servers - Run the playbook and verify the debug output
Commit your changes¶
- add all files to your git repo and commit it