-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.yml
182 lines (157 loc) · 5.11 KB
/
update.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# update.yml
---
- name: Upadte vm hosts
gather_facts: no
hosts: vm
tasks:
- name: Get os type
shell: cat /etc/os-release | grep '^ID=' | awk -F '=' '{print $2}'
register: os_type
- name: Apt update
shell: apt-get update
when: os_type.stdout == 'ubuntu' or os_type.stdout == 'debian'
register: apt_update
- name: Yum update
shell: yum update
when: os_type.stdout == 'centos' or os_type.stdout == 'fedora'
register: yum_update
- name: Apk update
shell: apk update
when: os_type.stdout == 'alpine'
register: apk_update
- name: Apt Upgrade
shell: apt-get dist-upgrade -y
when: os_type.stdout == 'ubuntu' or os_type.stdout == 'debian'
register: apt_upgrade
- name: Yum Upgrade
shell: yum upgrade -y
when: os_type.stdout == 'centos' or os_type.stdout == 'fedora'
register: yum_upgrade
- name: Apk Upgrade
shell: apk upgrade
when: os_type.stdout == 'alpine'
register: apk_upgrade
- name: Apt Clean
shell: apt-get autoremove -y && apt-get clean
when: os_type.stdout == 'ubuntu' or os_type.stdout == 'debian'
register: apt_clean
- name: Yum Clean
shell: yum clean all
when: os_type.stdout == 'centos' or os_type.stdout == 'fedora'
register: yum_clean
- name: Apk Clean
shell: apk cache clean
when: os_type.stdout == 'alpine'
- name: Apt result
when: os_type.stdout == 'ubuntu' or os_type.stdout == 'debian'
debug:
msg:
update: "{{ apt_update.stdout.split('\n') }}"
upgrade: "{{ apt_upgrade.stdout.split('\n') }}"
clean: "{{ apt_clean.stdout.split('\n') }}"
- name: Yum result
when: os_type.stdout == 'centos' or os_type.stdout == 'fedora'
debug:
msg:
update: "{{ yum_update.stdout.split('\n') }}"
upgrade: "{{ yum_upgrade.stdout.split('\n') }}"
clean: "{{ yum_clean.stdout.split('\n') }}"
- name: Apk result
when: os_type.stdout == 'alpine'
debug:
msg:
update: "{{ apk_update.stdout.split('\n') }}"
upgrade: "{{ apk_upgrade.stdout.split('\n') }}"
- name: Run script on LXC hosts
gather_facts: no
hosts: lxc
connection: local
tasks:
- name: Get os type
pct:
cmd: "exec"
host: "{{ inventory_hostname }}"
extra_args: source /etc/os-release && echo $ID
register: os_type
- name: Apt update
pct:
cmd: "exec"
host: "{{ inventory_hostname }}"
extra_args: "apt-get update"
when: os_type.output == 'ubuntu' or os_type.output == 'debian'
register: apt_update
- name: Yum update
pct:
cmd: "exec"
host: "{{ inventory_hostname }}"
extra_args: "yum update"
when: os_type.output == 'centos' or os_type.output == 'fedora'
register: yum_update
- name: Apk update
pct:
cmd: "exec"
host: "{{ inventory_hostname }}"
extra_args: "apk update"
when: os_type.output == 'alpine'
register: apk_update
- name: Apt Upgrade
pct:
cmd: "exec"
host: "{{ inventory_hostname }}"
extra_args: "apt-get dist-upgrade -y"
when: os_type.output == 'ubuntu' or os_type.output == 'debian'
register: apt_upgrade
- name: Yum Upgrade
pct:
cmd: "exec"
host: "{{ inventory_hostname }}"
extra_args: "yum upgrade -y"
when: os_type.output == 'centos' or os_type.output == 'fedora'
register: yum_upgrade
- name: Apk Upgrade
pct:
cmd: "exec"
host: "{{ inventory_hostname }}"
extra_args: "apk upgrade"
when: os_type.output == 'alpine'
register: apk_upgrade
- name: Apt Clean
pct:
cmd: "exec"
host: "{{ inventory_hostname }}"
extra_args: "apt-get autoremove -y && apt-get clean"
when: os_type.output == 'ubuntu' or os_type.output == 'debian'
register: apt_clean
- name: Yum Clean
pct:
cmd: "exec"
host: "{{ inventory_hostname }}"
extra_args: "yum clean all"
when: os_type.output == 'centos' or os_type.output == 'fedora'
register: yum_clean
- name: Apk Clean
pct:
cmd: "exec"
host: "{{ inventory_hostname }}"
extra_args: "apk cache clean"
when: os_type.output == 'alpine'
- name: Apt result
when: os_type.output == 'ubuntu' or os_type.output == 'debian'
debug:
msg:
update: "{{ apt_update.output.split('\n') }}"
upgrade: "{{ apt_upgrade.output.split('\n') }}"
clean: "{{ apt_clean.output.split('\n') }}"
- name: Yum result
when: os_type.output == 'centos' or os_type.output == 'fedora'
debug:
msg:
update: "{{ yum_update.output.split('\n') }}"
upgrade: "{{ yum_upgrade.output.split('\n') }}"
clean: "{{ yum_clean.output.split('\n') }}"
- name: Apk result
when: os_type.output == 'alpine'
debug:
msg:
update: "{{ apk_update.output.split('\n') }}"
upgrade: "{{ apk_upgrade.output.split('\n') }}"