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_serversand 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_settingswith these key/values- driftfile ->
/var/lib/ntp/ntp.drift - restrict ->
127.0.0.1 - statistics ->
loopstats peerstats clockstats
- driftfile ->
# 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
telnetviayummodule onweb2.<firstname>.lab - Run the installation again
- Remove the package
telnetviayummodule onweb2.<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
treeviaaptmodule onweb1.<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
ntpinstallation viaapt. Save the tasks also in the filelab4.ymlstate-> latest
# file: lab4.yml
- name: install ntp package
apt:
name: ntp
state: latest
Optional¶
Expand your dictionary¶
Replace the string
restrictwith 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
httpdversion2.4.6-88.el7.centosviayummodule onweb2.<firstname>.lab
ansible -m yum -a "name=httpd-2.4.6-88.el7.centos state=present" web2.pascal.lab