Lab 5 - Solution¶
Mandatory¶
Your first playbook¶
- Connect to your
srv.<firstname>.labasansibleuser - 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.<firstname>.lab - Add the already created task ntp installation from lab4
- Run your playbook (you will see changes)
- Run the playbook again (no changes)
# file: ntp-debian.yml
---
- hosts: web1.pascal.lab
tasks:
- name: install ntp
apt:
name: ntp
state: latest
# 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.<firstname>.lab - Create a task in YAML style for a
ntpinstallation viayum - Run the playbook in the check-mode (
--check) - Run your playbook (you will see changes)
- Run the playbook again (no changes)
# file: ntp-redhat.yml
---
- hosts: web2.pascal.lab
tasks:
- name: install ntp
yum:
name: ntp
state: latest
# 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.ymlImport both playbooks
ntp-redhat.ymlntp-debian.yml
Run the playbook step-by-step (
--step)
# file: ntp.yml
---
- import_playbook: ntp-debian.yml
- import_playbook: ntp-redhat.yml
ansible-playbook --step ntp.yml
Commit your changes¶
- add all files to your git repo and commit it
git add *
git commit -m 'added ntp playbooks'