Lab 7 - Variables & Roles Variables """"""""""""""""""""""""""""""""""" Mandatory ========= Host Groups ----------- * Edit your existing inventory file ``hosts`` * Create the host_group ``web`` and add your webservers * Create the host_group ``db`` and add your dbserver * Run the ping module to test the new host groups ``web`` and ``db`` group_vars ---------- * Create the ``group_vars`` directory in ``/home/ansible/training`` * Create ``group_vars/all.yml`` * add the variable ``myvar`` with the value ``variable for all servers`` * Run a task (ad-hoc or in playbook) on **all** servers to print out the variable ``myvar`` with the `Debug Module `_ * Add the variable ``myvar`` with the value ``variable for web servers`` only for the ``web`` group * Run a task (ad-hoc or in playbook) on **all** servers to print out the variable ``myvar`` with the `Debug Module `_ host_vars --------- * Create the ``host_vars`` directory in ``/home/ansible/training`` * Create a host variable file for the server ``web1..lab`` * Add the variable ``myvar`` with the value ``host variable for web1`` * Run a task (ad-hoc or in playbook) on **all** servers to print out the variable ``myvar`` with the `Debug Module `_ Role Variables & Loops ---------------------- * Extend your ``ntp`` role * Create a ``vars/main.yml`` file * Add list variable ``ntp_packages`` with the items ``ntp`` & ``ntpdate`` * Rewrite your ``tasks/main.yml`` * use the new defined variable ``ntp_packages`` in combination with ``with_items`` to install both packages (see Chapter Variables) * Run the playbook Role Default Variables ---------------------- * Extend your ``ntp`` role * Create a ``defaults/main.yml`` file * Add a list of servers to a new variable ``ntp_servers`` (you can use your example from your **lab4.yml**) * Extend the ``tasks/main.yml`` with a debug task to print out the defined list variable ``ntp_servers`` * Run the playbook and verify the debug output Commit your changes ------------------- * add all files to your git repo and commit it