Lab 5 - Solution """""""""""""""" Mandatory ========= Your first playbook ------------------- * Connect to your ``srv..lab`` as ``ansible`` user * Switch into your git repo ``/home/ansible/training`` * create a playbook with the filename ``ntp-debian.yml`` * The playbook should run on the host ``web1..lab`` * Add the already created task **ntp installation** from lab4 * Run your playbook (you will see changes) * Run the playbook again (no changes) .. code-block:: yaml # file: ntp-debian.yml --- - hosts: web1.pascal.lab tasks: - name: install ntp apt: name: ntp state: latest .. code-block:: bash # run 1 - changed ansible-playbook ntp-debian.yml # run 2 - ok ansible-playbook ntp-debian.yml Second playbook --------------- * create a playbook with the filename ``ntp-redhat.yml`` * The playbook will run on host ``web2..lab`` * Create a task in YAML style for a ``ntp`` installation via ``yum`` * Run the playbook in the check-mode (``--check``) * Run your playbook (you will see changes) * Run the playbook again (no changes) .. code-block:: yaml # file: ntp-redhat.yml --- - hosts: web2.pascal.lab tasks: - name: install ntp yum: name: ntp state: latest .. code-block:: bash # run 1 - check mode ansible-playbook --check ntp-redhat.yml # run 1 - changed ansible-playbook ntp-redhat.yml # run 2 - ok ansible-playbook ntp-redhat.yml Import playbooks ---------------- * Create a new playbook named ``ntp.yml`` * Import both playbooks * ``ntp-redhat.yml`` * ``ntp-debian.yml`` * Run the playbook step-by-step (``--step``) .. code-block:: yaml # file: ntp.yml --- - import_playbook: ntp-debian.yml - import_playbook: ntp-redhat.yml .. code-block:: bash ansible-playbook --step ntp.yml Commit your changes ------------------- * add all files to your git repo and commit it .. code-block:: bash git add * git commit -m 'added ntp playbooks'