Skip to content

Commit 7ea1b54

Browse files
authored
fix: move some templates to files (#11)
Some of the templates cannot be embedded because they themselves contain jinja. For now this is a quick hack to make them work. If we need any in the long term i will clean this up and find a less hacky solution, there is quite the chance that we will not need the currently affected tempaltes anyway in the long run
1 parent 1495fb3 commit 7ea1b54

File tree

4 files changed

+132
-122
lines changed

4 files changed

+132
-122
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
- hosts: all
3+
tasks:
4+
- command: ansible-galaxy install {{ item }} -p <%= input('location').present? ? input('location') : '/etc/ansible/roles' %>
5+
register: out
6+
with_items:
7+
- <%= input('ansible_roles_list') %>
8+
- debug: var=out
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
- hosts: all
3+
tasks:
4+
- name: Gather the rpm package facts
5+
package_facts:
6+
manager: auto
7+
8+
- name: Fail if the target server is a Satellite server
9+
fail:
10+
msg: "This playbook cannot be executed on a Satellite server. Use only on a Capsule server."
11+
when: "'satellite' in ansible_facts.packages"
12+
13+
- name: Install|Update satellite-maintain if not present
14+
package:
15+
name: rubygem-foreman_maintain
16+
state: latest
17+
18+
- block:
19+
<%- whitelist_option = if input('whitelist_options').present?
20+
"--whitelist=#{input('whitelist_options')}"
21+
end -%>
22+
- name: Upgrade Capsule server using satellite-maintain
23+
shell: satellite-maintain upgrade run --assumeyes --target-version=<%= input('target_version') %> <%= whitelist_option %>
24+
register: result
25+
26+
- name: Re-Gather the rpm package facts after the upgrade
27+
package_facts:
28+
manager: auto
29+
30+
- name: satellite-maintain upgrade return code is zero
31+
debug:
32+
msg: "Success! Capsule server upgrade completed. Current version of Capsule server server is {{ ansible_facts.packages['satellite-capsule'][0]['version'] }}."
33+
34+
rescue:
35+
- name: Print satellite-maintain output
36+
debug:
37+
var: result
38+
39+
- name: Grep top 10 Error messages from /var/log/foreman-installer/capsule.log
40+
shell: grep '^\[ERROR' /var/log/foreman-installer/capsule.log | head -n10
41+
register: output_grep
42+
43+
- name: Print grepped Error messages
44+
debug:
45+
var: output_grep.stdout_lines
46+
47+
- name: satellite-maintain upgrade return code is non-zero
48+
fail:
49+
msg: "Failed! Capsule server upgrade failed. See /var/log/foreman-installer/capsule.log in the Capsule server for more information"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
- hosts: all
2+
vars:
3+
updates: []
4+
<% if input('state').blank? %>
5+
state: searched
6+
<% else %>
7+
state: <%= input('state') %>
8+
<% end %>
9+
10+
tasks:
11+
- name: "{{ state | replace('ed','') | capitalize }} Windows Updates"
12+
win_updates:
13+
<% unless input('reject_list').blank? %>
14+
blacklist: <%= input('reject_list') %>
15+
<% end -%>
16+
<% if input('category_names').blank? %>
17+
category_names: ["CriticalUpdates", "SecurityUpdates", "UpdateRollups"]
18+
<% else %>
19+
category_names: <%= input('category_names') %>
20+
<% end %>
21+
<% unless input('log_path').blank? %>
22+
log_path: <%= input('log_path') %>
23+
<% end -%>
24+
<% if input('reboot').blank? %>
25+
reboot: false
26+
<% else %>
27+
reboot: <%= input('reboot') %>
28+
<% end %>
29+
<% if input('reboot_timeout').blank? %>
30+
reboot_timeout: 1200
31+
<% else %>
32+
reboot_timeout: <%= input('reboot_timeout') %>
33+
<% end -%>
34+
<% if input('server_selection').blank? %>
35+
server_selection: default
36+
<% else %>
37+
server_selection: <%= input('server_selection') %>
38+
<% end %>
39+
state: "{{ state }}"
40+
<% if input('use_scheduled_task').blank? %>
41+
use_scheduled_task: false
42+
<% else %>
43+
use_scheduled_task: <%= input('use_scheduled_task') %>
44+
<% end %>
45+
<% if !input('whitelist').blank? %>
46+
whitelist: <%= input('whitelist') %>
47+
<% end -%>
48+
49+
register: found_updates
50+
51+
- name: "Get all {{ state }} updates"
52+
set_fact:
53+
updates: "{{ updates + [ current_update ] }}"
54+
vars:
55+
current_update: "{{ item.value.title }}"
56+
loop: "{{ found_updates.updates | dict2items }}"
57+
no_log: true
58+
59+
- name: "List {{ state }} Windows Updates"
60+
debug:
61+
msg: "{{ item }}"
62+
loop: "{{ updates }}"

roles/foreman/tasks/job_templates.yaml

+13-122
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@
132132
advanced: true
133133
value_type: plain
134134
hidden_value: false
135-
template: |
136-
---
137-
- hosts: all
138-
tasks:
139-
- command: ansible-galaxy install {{ item }} -p <%= input('location').present? ? input('location') : '/etc/ansible/roles' %>
140-
register: out
141-
with_items:
142-
- <%= input('ansible_roles_list') %>
143-
- debug: var=out
135+
#
136+
# This is a hack because i am too lazy to look up how to use /files/ properly.
137+
# I'm only doing it for the affected templates and not all of them.
138+
#
139+
# All of these templates are somewhat an artifact of bootstrapping foreman and will
140+
# we removed when we're closer to v1.
141+
#
142+
# TODO: get rid of ugly hack
143+
file_name: /etc/ansible/collections/ansible_collections/radiorabe/rabe_foreman/roles/foreman/files/ansible_roles__install_from_galay.erb
144144
- name: Ansible Roles - Install from git
145145
state: present
146146
description_format: 'Clone roles from git repository to %{location}'
@@ -251,56 +251,8 @@
251251
advanced: false
252252
value_type: plain
253253
hidden_value: false
254-
template: |
255-
---
256-
- hosts: all
257-
tasks:
258-
- name: Gather the rpm package facts
259-
package_facts:
260-
manager: auto
261-
262-
- name: Fail if the target server is a Satellite server
263-
fail:
264-
msg: "This playbook cannot be executed on a Satellite server. Use only on a Capsule server."
265-
when: "'satellite' in ansible_facts.packages"
266-
267-
- name: Install|Update satellite-maintain if not present
268-
package:
269-
name: rubygem-foreman_maintain
270-
state: latest
271-
272-
- block:
273-
<%- whitelist_option = if input('whitelist_options').present?
274-
"--whitelist=#{input('whitelist_options')}"
275-
end -%>
276-
- name: Upgrade Capsule server using satellite-maintain
277-
shell: satellite-maintain upgrade run --assumeyes --target-version=<%= input('target_version') %> <%= whitelist_option %>
278-
register: result
279-
280-
- name: Re-Gather the rpm package facts after the upgrade
281-
package_facts:
282-
manager: auto
283-
284-
- name: satellite-maintain upgrade return code is zero
285-
debug:
286-
msg: "Success! Capsule server upgrade completed. Current version of Capsule server server is {{ ansible_facts.packages['satellite-capsule'][0]['version'] }}."
287-
288-
rescue:
289-
- name: Print satellite-maintain output
290-
debug:
291-
var: result
292-
293-
- name: Grep top 10 Error messages from /var/log/foreman-installer/capsule.log
294-
shell: grep '^\[ERROR' /var/log/foreman-installer/capsule.log | head -n10
295-
register: output_grep
296-
297-
- name: Print grepped Error messages
298-
debug:
299-
var: output_grep.stdout_lines
300-
301-
- name: satellite-maintain upgrade return code is non-zero
302-
fail:
303-
msg: "Failed! Capsule server upgrade failed. See /var/log/foreman-installer/capsule.log in the Capsule server for more information"
254+
# TODO: get rid of ugly hack
255+
file_name: /etc/ansible/collections/ansible_collections/radiorabe/rabe_foreman/roles/foreman/files/capsule_upgrade_playbook.erb
304256
- name: Change content source
305257
state: present
306258
description_format: Configure subscription manager to new content source
@@ -770,69 +722,8 @@
770722
advanced: false
771723
value_type: plain
772724
hidden_value: false
773-
template: |
774-
- hosts: all
775-
vars:
776-
updates: []
777-
<% if input('state').blank? %>
778-
state: searched
779-
<% else %>
780-
state: <%= input('state') %>
781-
<% end %>
782-
783-
tasks:
784-
- name: "{{ state | replace('ed','') | capitalize }} Windows Updates"
785-
win_updates:
786-
<% unless input('reject_list').blank? %>
787-
blacklist: <%= input('reject_list') %>
788-
<% end -%>
789-
<% if input('category_names').blank? %>
790-
category_names: ["CriticalUpdates", "SecurityUpdates", "UpdateRollups"]
791-
<% else %>
792-
category_names: <%= input('category_names') %>
793-
<% end %>
794-
<% unless input('log_path').blank? %>
795-
log_path: <%= input('log_path') %>
796-
<% end -%>
797-
<% if input('reboot').blank? %>
798-
reboot: false
799-
<% else %>
800-
reboot: <%= input('reboot') %>
801-
<% end %>
802-
<% if input('reboot_timeout').blank? %>
803-
reboot_timeout: 1200
804-
<% else %>
805-
reboot_timeout: <%= input('reboot_timeout') %>
806-
<% end -%>
807-
<% if input('server_selection').blank? %>
808-
server_selection: default
809-
<% else %>
810-
server_selection: <%= input('server_selection') %>
811-
<% end %>
812-
state: "{{ state }}"
813-
<% if input('use_scheduled_task').blank? %>
814-
use_scheduled_task: false
815-
<% else %>
816-
use_scheduled_task: <%= input('use_scheduled_task') %>
817-
<% end %>
818-
<% if !input('whitelist').blank? %>
819-
whitelist: <%= input('whitelist') %>
820-
<% end -%>
821-
822-
register: found_updates
823-
824-
- name: "Get all {{ state }} updates"
825-
set_fact:
826-
updates: "{{ updates + [ current_update ] }}"
827-
vars:
828-
current_update: "{{ item.value.title }}"
829-
loop: "{{ found_updates.updates | dict2items }}"
830-
no_log: true
831-
832-
- name: "List {{ state }} Windows Updates"
833-
debug:
834-
msg: "{{ item }}"
835-
loop: "{{ updates }}"
725+
# TODO: get rid of ugly hack
726+
file_name: /etc/ansible/collections/ansible_collections/radiorabe/rabe_foreman/roles/foreman/files/manage_windows_updates.erb
836727
- name: Module Action - Ansible Default
837728
state: present
838729
description_format: 'Module %{action} %{module_spec}'

0 commit comments

Comments
 (0)