Refactor the whole playbook in a block

Also switch the condition, since it is possible that
future EL version might use dnf, so checking on Fedora
distribution is less future-proof than using the pkg_mgr
from ansible.
This commit is contained in:
Michael Scherer 2016-08-08 10:36:47 +02:00 committed by Kevin Fenzi
parent 186b357b48
commit 5cce9c0030

View file

@ -5,40 +5,37 @@
# We want this on any public facing Fedora installs so we # We want this on any public facing Fedora installs so we
# can pick up security updates. # can pick up security updates.
# #
- block:
- name: install dnf-automatic
dnf:
name: dnf-automatic
state: present
tags:
- packages
- name: install dnf-automatic - name: install /etc/dnf/automatic.conf
dnf: template:
name: dnf-automatic src: automatic.conf.j2
state: present dest: /etc/dnf/automatic.conf
tags: mode: 0644
- packages tags:
when: ansible_distribution == 'Fedora' and ansible_distribution_major_version|int > 21 - config
- name: install /etc/dnf/automatic.conf - name: enable and start dnf-automatic
template: command: systemctl enable dnf-automatic.timer
src: automatic.conf.j2 args:
dest: /etc/dnf/automatic.conf creates: /etc/systemd/system/basic.target.wants/dnf-automatic.timer
mode: 0644 tags:
tags: - config
- config
when: ansible_distribution == 'Fedora' and ansible_distribution_major_version|int > 21
- name: enable and start dnf-automatic - name: check if dnf-automatic.timer is active
command: systemctl enable dnf-automatic.timer command: systemctl is-active dnf-automatic.timer
args: register: automaticative
creates: /etc/systemd/system/basic.target.wants/dnf-automatic.timer always_run: yes
tags: changed_when: 1 != 1
- config ignore_errors: true
when: ansible_distribution == 'Fedora' and ansible_distribution_major_version|int > 21
- name: check if dnf-automatic.timer is active - name: start dnf-automatic.timer if it is not active
command: systemctl is-active dnf-automatic.timer command: systemctl start dnf-automatic.timer
register: automaticative when: automaticative|failed
always_run: yes when: ansible_pkg_mgr = 'dnf'
changed_when: 1 != 1
ignore_errors: true
when: ansible_distribution == 'Fedora' and ansible_distribution_major_version|int > 21
- name: start dnf-automatic.timer if it is not active
command: systemctl start dnf-automatic.timer
when: automaticative|failed and ansible_distribution == 'Fedora' and ansible_distribution_major_version|int > 21