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
# can pick up security updates.
#
- block:
- name: install dnf-automatic
dnf:
name: dnf-automatic
state: present
tags:
- packages
- name: install dnf-automatic
dnf:
name: dnf-automatic
state: present
tags:
- packages
when: ansible_distribution == 'Fedora' and ansible_distribution_major_version|int > 21
- name: install /etc/dnf/automatic.conf
template:
src: automatic.conf.j2
dest: /etc/dnf/automatic.conf
mode: 0644
tags:
- config
- name: install /etc/dnf/automatic.conf
template:
src: automatic.conf.j2
dest: /etc/dnf/automatic.conf
mode: 0644
tags:
- config
when: ansible_distribution == 'Fedora' and ansible_distribution_major_version|int > 21
- name: enable and start dnf-automatic
command: systemctl enable dnf-automatic.timer
args:
creates: /etc/systemd/system/basic.target.wants/dnf-automatic.timer
tags:
- config
- name: enable and start dnf-automatic
command: systemctl enable dnf-automatic.timer
args:
creates: /etc/systemd/system/basic.target.wants/dnf-automatic.timer
tags:
- config
when: ansible_distribution == 'Fedora' and ansible_distribution_major_version|int > 21
- name: check if dnf-automatic.timer is active
command: systemctl is-active dnf-automatic.timer
register: automaticative
always_run: yes
changed_when: 1 != 1
ignore_errors: true
- name: check if dnf-automatic.timer is active
command: systemctl is-active dnf-automatic.timer
register: automaticative
always_run: yes
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
- name: start dnf-automatic.timer if it is not active
command: systemctl start dnf-automatic.timer
when: automaticative|failed
when: ansible_pkg_mgr = 'dnf'