-
Notifications
You must be signed in to change notification settings - Fork 0
/
rhel-like_patching.yml
61 lines (58 loc) · 1.64 KB
/
rhel-like_patching.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
---
- name: check RHEL agents and subscription state
become: yes
gather_facts: yes
hosts:
- all
vars_files:
- vars/vault
roles:
- { role: redhataccess.redhat-access-insights-client, when: ansible_distribution == "RedHat" }
tasks:
- block:
- name: check to see if system is already registered
command: subscription-manager status
register: sub_status
ignore_errors: true
- name: Register system
redhat_subscription:
state: present
username: "{{ rhn_user }}"
password: "{{ rhn_pass }}"
pool_ids: "{{ rhn_pool_id }}"
when: sub_status.rc == 1
when: ansible_distribution == "RedHat" and not ansible_domain == "ec2.internal"
- name: Patch RHEL/CentOS server(s)
become: "yes"
gather_facts: "no"
hosts:
- all
tasks:
- name: Downloading updates
command: yum update --downloadonly
ignore_warnings: yes
- name: Update all available packages
yum: name=* state=latest
notify: reboot sequence
handlers:
- name: reboot sequence
changed_when: "true"
debug: msg='trigger machine reboot sequence'
notify:
- reboot system
- waiting for server to come back
- name: reboot system
shell: sleep 2 && shutdown -r now "Ansible package updates triggered"
async: 1
poll: 0
ignore_errors: true
register: reboot
- name: waiting for server to come back
become: false
local_action:
module: wait_for
host={{ ansible_hostname }}
port=22
delay=1
timeout=300
when: reboot is defined