Lab 4 - Solution

Mandatory

Create a YAML List

  • create an empty file and save it as lab4.yml
touch lab4.yml
vi lab4.yml
  • edit the file and define a YAML list named ntp_servers and add this items:

    • 0.ch.pool.ntp.org
    • 1.ch.pool.ntp.org
    • 2.ch.pool.ntp.org
    • 3.ch.pool.ntp.org
# file: lab4.yml
---
ntp_servers:
  - 0.ch.pool.ntp.org
  - 1.ch.pool.ntp.org
  - 2.ch.pool.ntp.org
  - 3.ch.pool.ntp.org

Create a YAML dictionary

  • add a dictionary named ntp_settings with these key/values

    • driftfile -> /var/lib/ntp/ntp.drift
    • restrict -> 127.0.0.1
    • statistics -> loopstats peerstats clockstats
# file: lab4.yml
# a dictionary
ntp_settings:
  driftfile: /var/lib/ntp/ntp.drift
  restrict: 127.0.0.1
  statistics: loopstats peerstats clockstats

Run some ad-hoc tasks

  • Install telnet via yum module on web2.<firstname>.lab
  • Run the installation again
  • Remove the package telnet via yum module on web2.<firstname>.lab
  • Run the deinstallation again
# install 1 - changed
ansible -m yum -a "name=telnet state=latest" web2.pascal.lab

# install 2 - ok
ansible -m yum -a "name=telnet state=latest" web2.pascal.lab

# deinstall 1 - changed
ansible -m yum -a "name=telnet state=absent" web2.pascal.lab

# install 2 - ok
ansible -m yum -a "name=telnet state=absent" web2.pascal.lab

Install tree

  • Install tree via apt module on web1.<firstname>.lab
# install 1 - changed
ansible -m apt -a "name=tree state=latest" web1.pascal.lab

Create your first YAML task

  • Create a task in YAML style for a ntp installation via apt. Save the tasks also in the file lab4.yml

    • state -> latest
# file: lab4.yml
- name: install ntp package
  apt:
    name: ntp
    state: latest

Optional

Expand your dictionary

  • Replace the string restrict with a list and add these items:

    • 127.0.0.1
    • ::1
# a dictionary
ntpsettings:
  driftfile: /var/lib/ntp/ntp.drift
  restrict:
    - 127.0.0.1
    - ::1
  statistics: loopstats peerstats clockstats

Install a specific version of a package

  • Install httpd version 2.4.6-88.el7.centos via yum module on web2.<firstname>.lab
ansible -m yum -a "name=httpd-2.4.6-88.el7.centos state=present" web2.pascal.lab