Skip to content

Commit 1e629cc

Browse files
committed
fix(awx): prevented var collision by prefixing with nfc_pb_awx
awx itself uses var prefix `awx_` !26
1 parent c0ae4ee commit 1e629cc

12 files changed

+202
-160
lines changed

awx.yaml

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66

77
tasks:
88

9+
910
- name: Organizations
1011
ansible.builtin.include_tasks:
1112
file: tasks/awx/organization.yaml
12-
loop: "{{ awx_config.organizations }}"
13+
loop: "{{ my_awx_config.organizations }}" # Fix as this var should be dynamic
1314
loop_control:
14-
loop_var: awx_organization
15+
loop_var: nfc_pb_awx_organization
1516

1617

1718
vars:
1819
ansible_connection: local
19-
awx_tower_template:
20+
nfc_pb_awx_tower_template:
2021
- name: "AWX / Tower Configure"
2122
ask_tags_on_launch: false
2223
ask_inventory_on_launch: true
@@ -40,9 +41,9 @@
4041
"min": 3,
4142
"type": "text",
4243
"choices": "",
43-
"default": "awx_config",
44+
"default": "my_awx_config",
4445
"required": true,
45-
"variable": "awx_config_variable",
46+
"variable": "nfc_pb_awx_config_variable",
4647
"new_question": true,
4748
"question_name": "Inventory Variable",
4849
"question_description": "The Variable in the Inventory the AWX config is under"
@@ -65,7 +66,7 @@
6566
# max_concurrent_jobs: "{{ item[0].max_concurrent_jobs | default('0') }}"
6667
# max_forks: "{{ item[0].max_forks | default('0') }}"
6768
# state: "{{ item[1].state | default('present') }}"
68-
# when: awx_config is defined and awx_config.organizations is defined and item[1]|length > 0
69+
# when: nfc_pb_awx_config is defined and nfc_pb_awx_config.organizations is defined and item[1]|length > 0
6970
# #with_items: "{{ awx.organizations }}.instance_groups"
7071
# # with_list: "{{ awx.organizations.instance_groups }}"
7172
# with_subelements:
@@ -78,14 +79,14 @@
7879
# name: "{{ item[1].name }}"
7980
# inventory: "{{ item[1].name }}"
8081
# organization: "{{ item[0].name }}"
81-
# controller_host: "{{ awx_controller_host | default(omit) }}"
82-
# controller_oauthtoken: "{{ awx_controller_oauthtoken | default(omit) }}"
83-
# controller_username: "{{ awx_controller_username | default(omit) }}"
84-
# controller_password: "{{ awx_controller_password | default(omit) }}"
82+
# controller_host: "{{ nfc_pb_awx_controller_host | default(omit) }}"
83+
# controller_oauthtoken: "{{ nfc_pb_awx_controller_oauthtoken | default(omit) }}"
84+
# controller_username: "{{ nfc_pb_awx_controller_username | default(omit) }}"
85+
# controller_password: "{{ nfc_pb_awx_controller_password | default(omit) }}"
8586
# with_subelements:
86-
# - "{{ awx_config_variable.organizations }}"
87+
# - "{{ nfc_pb_awx_config_variable.organizations }}"
8788
# - projects
88-
# when: awx_config is defined and awx_config.organizations is defined and item[1] | length > 0
89+
# when: nfc_pb_awx_config is defined and nfc_pb_awx_config.organizations is defined and item[1] | length > 0
8990
# # no_log: true
9091
# diff: true
9192
# tags:
@@ -99,10 +100,10 @@
99100
# #
100101
# - name: Schedule configuration
101102
# awx.awx.schedule:
102-
# controller_host: "{{ awx_controller_host | default(omit) }}"
103-
# controller_oauthtoken: "{{ awx_controller_oauthtoken | default(omit) }}"
104-
# controller_username: "{{ awx_controller_username | default(omit) }}"
105-
# controller_password: "{{ awx_controller_password | default(omit) }}"
103+
# controller_host: "{{ nfc_pb_awx_controller_host | default(omit) }}"
104+
# controller_oauthtoken: "{{ nfc_pb_awx_controller_oauthtoken | default(omit) }}"
105+
# controller_username: "{{ nfc_pb_awx_controller_username | default(omit) }}"
106+
# controller_password: "{{ nfc_pb_awx_controller_password | default(omit) }}"
106107
# name: "{{ item[1].name }}"
107108
# state: "{{ item[1].state | default('present') }}"
108109
# scm_branch: "{{ item[1].scm_branch | default(omit) }}"
@@ -111,7 +112,7 @@
111112
# job_type: "{{ item[1].job_type }}"
112113
# rrule: "{{ query('awx.awx.schedule_rrule', item[1].schedule.terms, every=item[1].schedule.every, timezone=item[1].schedule.timezone) }}" # "{{ item[1].schedule }}"
113114
# with_subelements:
114-
# - "{{ awx_config.organizations }}"
115+
# - "{{ nfc_pb_awx_config.organizations }}"
115116
# - schedules
116117
# # no_log: true
117118
# diff: true

backup.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070

7171
vars:
7272

73-
awx_tower_template:
73+
nfc_pb_awx_tower_template:
7474
- name: "Backup(s) from Inventory config"
7575
ask_limit_on_launch: true
7676
ask_tags_on_launch: true

git_configuration.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
vars:
1313
ansible_connection: local
14-
awx_tower_template:
14+
nfc_pb_awx_tower_template:
1515
- name: "Configure Gitlab / Github Repositories"
1616
ask_tags_on_launch: true
1717
ask_inventory_on_launch: true

kubernetes.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
common_gather_facts: true
1313

1414
vars:
15-
awx_tower_template:
15+
nfc_pb_awx_tower_template:
1616
- name: "Kubernetes"
1717
ask_tags_on_launch: true
1818
ask_limit_on_launch: true

postgres.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
postgresDB_database_name: "" # String, Required
172172
postgresDB_filename_restore: "" # String, Required for Restore ONLY
173173

174-
awx_tower_template:
174+
nfc_pb_awx_tower_template:
175175
- name: "PostgresDB"
176176
ask_tags_on_launch: true
177177
description: |

tasks/awx/inventory.yaml

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
- name: Add inventory
33
awx.awx.inventory:
44
name: "Production"
5-
description: "{{ awx_inventory.description | default('') }}"
6-
controller_host: "{{ awx_controller_host | default(omit) }}"
7-
controller_oauthtoken: "{{ awx_controller_oauthtoken | default(omit) }}"
8-
controller_username: "{{ awx_controller_username | default(omit) }}"
9-
controller_password: "{{ awx_controller_password | default(omit) }}"
10-
organization: "{{ awx_organization.name }}"
5+
description: "{{ nfc_pb_awx_inventory.description | default('') }}"
6+
controller_host: "{{ nfc_pb_awx_controller_host | default(omit) }}"
7+
controller_oauthtoken: "{{ nfc_pb_awx_controller_oauthtoken | default(omit) }}"
8+
controller_username: "{{ nfc_pb_awx_controller_username | default(omit) }}"
9+
controller_password: "{{ nfc_pb_awx_controller_password | default(omit) }}"
10+
organization: "{{ nfc_pb_awx_organization.name }}"
1111
state: present
1212
validate_certs: "{{ validate_certs | default(true) }}"
1313
# no_log: true
@@ -16,37 +16,49 @@
1616

1717
- name: Add an inventory source
1818
awx.awx.inventory_source:
19+
name: "{{ nfc_pb_awx_project.name }}"
20+
description: "{{ nfc_pb_awx_inventory.description | default('') }}"
21+
controller_host: "{{ nfc_pb_awx_controller_host | default(omit) }}"
22+
controller_oauthtoken: "{{ nfc_pb_awx_controller_oauthtoken | default(omit) }}"
23+
controller_username: "{{ nfc_pb_awx_controller_username | default(omit) }}"
24+
controller_password: "{{ nfc_pb_awx_controller_password | default(omit) }}"
1925
validate_certs: "{{ validate_certs | default(true) }}"
26+
organization: "{{ nfc_pb_awx_organization.name }}"
2027
inventory: "Production"
2128
# credential: previously-created-credential
2229
# overwrite: True
2330
# update_on_launch: True
24-
source_project: "{{ awx_project.name }}"
31+
source_project: "{{ nfc_pb_awx_project.name }}"
2532
source_path: inventory/production/
2633
source: scm
2734
state: present
2835
verbosity: 2
29-
overwrite: "{{ awx_inventory.inventory_overwrite | default(true) | bool }}"
30-
overwrite_vars: "{{ awx_inventory.inventory_overwrite_vars | default(true) | bool }}"
31-
scm_branch: "{{ awx_inventory.scm_branch | default(omit) }}"
36+
overwrite: "{{ nfc_pb_awx_inventory.inventory_overwrite | default(true) | bool }}"
37+
overwrite_vars: "{{ nfc_pb_awx_inventory.inventory_overwrite_vars | default(true) | bool }}"
38+
scm_branch: "{{ nfc_pb_awx_inventory.scm_branch | default(omit) }}"
3239
# no_log: true
3340
diff: true
3441

3542

36-
- name: "Update inventory sources {{ awx_project.name }}/{{ awx_project.name }}"
43+
- name: "Update inventory sources {{ nfc_pb_awx_project.name }}/{{ nfc_pb_awx_project.name }}"
3744
awx.awx.inventory_source_update:
38-
name: "{{ awx_project.name }}"
45+
name: "{{ nfc_pb_awx_project.name }}"
3946
inventory: "Production"
47+
controller_host: "{{ nfc_pb_awx_controller_host | default(omit) }}"
48+
controller_oauthtoken: "{{ nfc_pb_awx_controller_oauthtoken | default(omit) }}"
49+
controller_username: "{{ nfc_pb_awx_controller_username | default(omit) }}"
50+
controller_password: "{{ nfc_pb_awx_controller_password | default(omit) }}"
51+
organization: "{{ nfc_pb_awx_organization.name }}"
4052
validate_certs: "{{ validate_certs | default(true) }}"
4153
# no_log: true
4254
diff: true
4355

4456

45-
- name: "RBAC - {{ awx_organization.name }}/Project/{{ awx_project.name }}/Inventory"
57+
- name: "RBAC - {{ nfc_pb_awx_organization.name }}/Project/{{ nfc_pb_awx_project.name }}/Inventory"
4658
ansible.builtin.include_tasks:
4759
file: tasks/awx/rbac.yaml
48-
loop: "{{ awx_project.rbac.inventory }}"
60+
loop: "{{ nfc_pb_awx_project.rbac.inventory }}"
4961
loop_control:
50-
loop_var: awx_rbac
62+
loop_var: nfc_pb_awx_rbac
5163
vars:
52-
awx_inventory_name: "Production"
64+
nfc_pb_awx_inventory_name: "Production"

tasks/awx/job_template.yaml

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,88 +5,96 @@
55
- name: Debug
66
ansible.builtin.debug:
77
msg:
8-
- "{{ awx_playbook_filename }}"
9-
- "{{ awx_job_template }}"
8+
- "{{ nfc_pb_awx_playbook_filename }}"
9+
- "{{ nfc_pb_awx_job_template }}"
10+
- "{{ nfc_pb_awx_job_template_name | default('Not Yet Defined') }}"
1011

1112
# - name: Create fact from Playbook
1213
# ansible.builtin.set_fact:
13-
# playbook_contents: "{{ lookup('file', awx_playbook_filename) | from_yaml }}"
14-
# when: awx_playbook_filename | default('') != ''
14+
# playbook_contents: "{{ lookup('file', nfc_pb_awx_playbook_filename) | from_yaml }}"
15+
# when: nfc_pb_awx_playbook_filename | default('') != ''
1516
# failed_when: false
1617

1718

1819
# - name: Job Template from Playbook
1920
# ansible.builtin.set_fact:
2021
# # playbook_contents: "{{ playbook_contents[0] }}"
21-
# # awx_name: "{{ playbook_contents[0].name }}"
22-
# awx_tower_template: "{{ awx_job_template.vars.awx_tower_template }}"
23-
# when: playbook_contents[0].vars.awx_tower_template | default([]) | length | int > 0
22+
# # nfc_pb_awx_name: "{{ playbook_contents[0].name }}"
23+
# nfc_pb_awx_tower_template: "{{ nfc_pb_awx_job_template.vars.nfc_pb_awx_tower_template }}"
24+
# when: playbook_contents[0].vars.nfc_pb_awx_tower_template | default([]) | length | int > 0
2425
# loop: "{{ playbook_contents }}"
2526
# loop_control:
2627
# loop_var: job_template
2728
# failed_when: false
2829

2930
- name: Create Labels
3031
awx.awx.label:
31-
controller_host: "{{ awx_controller_host | default(omit) }}"
32-
controller_oauthtoken: "{{ awx_controller_oauthtoken | default(omit) }}"
33-
controller_username: "{{ awx_controller_username | default(omit) }}"
34-
controller_password: "{{ awx_controller_password | default(omit) }}"
32+
controller_host: "{{ nfc_pb_awx_controller_host | default(omit) }}"
33+
controller_oauthtoken: "{{ nfc_pb_awx_controller_oauthtoken | default(omit) }}"
34+
controller_username: "{{ nfc_pb_awx_controller_username | default(omit) }}"
35+
controller_password: "{{ nfc_pb_awx_controller_password | default(omit) }}"
3536
name: "{{ item }}"
36-
organization: "{{ awx_organization.name }}"
37+
organization: "{{ nfc_pb_awx_organization.name }}"
3738
state: present
3839
validate_certs: "{{ validate_certs | default(true) }}"
40+
loop: "{{ nfc_pb_awx_job_template.labels | default([]) }}"
3941

4042

41-
- name: "Configure Job Template {{ awx_playbook_dir | default('') }}{{ awx_playbook_filename }}"
43+
- name: "Configure Job Template {{ nfc_pb_awx_playbook_dir | default('') }}{{ nfc_pb_awx_playbook_filename }}"
4244
awx.awx.job_template:
43-
name: "{{ awx_job_template.name }}"
44-
description: "{{ awx_job_template.description | default(omit) }}"
45-
controller_host: "{{ awx_controller_host | default(omit) }}"
46-
controller_oauthtoken: "{{ awx_controller_oauthtoken | default(omit) }}"
47-
controller_username: "{{ awx_controller_username | default(omit) }}"
48-
controller_password: "{{ awx_controller_password | default(omit) }}"
49-
execution_environment: "{{ awx_job_template.execution_environment | default(omit) }}"
50-
job_type: "{{ awx_job_template.job_type | default('run') }}"
51-
job_tags: "{{ awx_job_template.job_tags | default(omit) }}"
52-
organization: "{{ awx_organization.name }}"
53-
# inventory: "{{ awx_inventory.name | default(omit) }}"
54-
project: "{{ awx_project.name }}"
55-
playbook: "{{ awx_project.path | default('') }}{{ awx_playbook_filename }}"
56-
# scm_branch: "{{ awx_branch }}"
57-
ask_tags_on_launch: "{{ awx_job_template.ask_tags_on_launch | default(false) | bool }}"
58-
ask_inventory_on_launch: "{{ awx_job_template.ask_inventory_on_launch | default(true) | bool }}"
59-
credentials: "{{ awx_job_template.credentials | default(omit) }}"
60-
state: "{{ awx_job_template.state | default('present') }}"
61-
survey_enabled: "{{ awx_job_template.survey_enabled | default(false) | bool }}"
62-
# survey_spec: "{{ awx_job_template.survey_spec | from_yaml | to_json | default(omit) }}"
45+
name: "{{ nfc_pb_awx_job_template.name }}"
46+
description: "{{ nfc_pb_awx_job_template.description | default(omit) }}"
47+
controller_host: "{{ nfc_pb_awx_controller_host | default(omit) }}"
48+
controller_oauthtoken: "{{ nfc_pb_awx_controller_oauthtoken | default(omit) }}"
49+
controller_username: "{{ nfc_pb_awx_controller_username | default(omit) }}"
50+
controller_password: "{{ nfc_pb_awx_controller_password | default(omit) }}"
51+
execution_environment: "{{ nfc_pb_awx_job_template.execution_environment | default(omit) }}"
52+
job_type: "{{ nfc_pb_awx_job_template.job_type | default('run') }}"
53+
job_tags: "{{ nfc_pb_awx_job_template.job_tags | default(omit) }}"
54+
organization: "{{ nfc_pb_awx_organization.name }}"
55+
# inventory: "{{ nfc_pb_awx_inventory.name | default(omit) }}"
56+
project: "{{ nfc_pb_awx_project.name }}"
57+
playbook: "{{ nfc_pb_awx_project.path | default('') }}{{ nfc_pb_awx_playbook_filename }}"
58+
# scm_branch: "{{ nfc_pb_awx_branch }}"
59+
ask_tags_on_launch: "{{ nfc_pb_awx_job_template.ask_tags_on_launch | default(false) | bool }}"
60+
ask_inventory_on_launch: "{{ nfc_pb_awx_job_template.ask_inventory_on_launch | default(true) | bool }}"
61+
credentials: "{{ nfc_pb_awx_job_template.credentials | default(omit) }}"
62+
state: "{{ nfc_pb_awx_job_template.state | default('present') }}"
63+
survey_enabled: "{{ nfc_pb_awx_job_template.survey_enabled | default(false) | bool }}"
64+
# survey_spec: "{{ nfc_pb_awx_job_template.survey_spec | from_yaml | to_json | default(omit) }}"
6365
survey_spec: >-
64-
{%- if awx_job_template.survey_spec | default ('') == '' -%}
66+
{%- if nfc_pb_awx_job_template.survey_spec | default ('') == '' -%}
6567
{{ omit }}
6668
{%- else -%}
67-
{{ awx_job_template.survey_spec | from_yaml | to_json }}
69+
{{ nfc_pb_awx_job_template.survey_spec | from_yaml | to_json }}
6870
{%- endif -%}
71+
labels: "{{ nfc_pb_awx_job_template.labels | default(omit) }}"
72+
verbosity: "{{ nfc_pb_awx_job_template.verbosity | default(2) }}"
73+
ask_scm_branch_on_launch: "{{ nfc_pb_awx_job_template.ask_scm_branch_on_launch | default(false) | bool }}"
74+
ask_limit_on_launch: "{{ nfc_pb_awx_job_template.ask_limit_on_launch | default(false) | bool }}"
75+
ask_job_type_on_launch: "{{ nfc_pb_awx_job_template.ask_job_type_on_launch | default(true) | bool }}"
76+
use_fact_cache: "{{ nfc_pb_awx_job_template.use_fact_cache | default(true) | bool }}"
6977
validate_certs: "{{ validate_certs | default(true) }}"
7078
# no_log: true
71-
when: awx_tower_template | default('') != ''
79+
when: nfc_pb_awx_tower_template | default('') != ''
7280
diff: true
7381

7482

75-
- name: "RBAC - {{ awx_organization.name }}/Project/{{ awx_project.name }}/Job/{{ awx_job_template.name }}"
83+
- name: "RBAC - {{ nfc_pb_awx_organization.name }}/Project/{{ nfc_pb_awx_project.name }}/Job/{{ nfc_pb_awx_job_template.name }}"
7684
ansible.builtin.include_tasks:
7785
file: tasks/awx/rbac.yaml
78-
loop: "{{ awx_project.rbac.job }}"
86+
loop: "{{ nfc_pb_awx_project.rbac.job }}"
7987
loop_control:
80-
loop_var: awx_rbac
88+
loop_var: nfc_pb_awx_rbac
8189
when:
8290
(
83-
awx_project.type | lower == 'playbook'
91+
nfc_pb_awx_project.type | lower == 'playbook'
8492
or
85-
awx_project.type | lower == 'both'
93+
nfc_pb_awx_project.type | lower == 'both'
8694
)
8795
vars:
88-
job_template_name: "{{ awx_job_template.name }}"
96+
nfc_pb_awx_job_template_name: "{{ nfc_pb_awx_job_template.name }}"
8997

9098
# - name: Fact Cleanup - job_template
9199
# ansible.builtin.set_fact:
92-
# awx_tower_template:
100+
# nfc_pb_awx_job_template_name:

tasks/awx/job_templates.yaml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
- name: Debug
44
ansible.builtin.debug:
55
msg:
6-
- "{{ awx_playbook_filename }}"
6+
- "{{ nfc_pb_awx_playbook_filename }}"
77

88

99
- name: Create fact from Playbook
1010
ansible.builtin.set_fact:
11-
awx_tower_templates: []
12-
playbook_contents: "{{ lookup('file', item.root + awx_playbook_filename) | from_yaml }}"
13-
when: awx_playbook_filename | default('') != ''
11+
nfc_pb_awx_tower_templates: []
12+
playbook_contents: "{{ lookup('file', item.root + nfc_pb_awx_playbook_filename) | from_yaml }}"
13+
when: nfc_pb_awx_playbook_filename | default('') != ''
1414
failed_when: false
1515

1616

@@ -22,7 +22,7 @@
2222

2323
- name: Job Template from Playbook
2424
ansible.builtin.set_fact:
25-
awx_tower_templates: "{{ awx_tower_templates + job_template.vars.awx_tower_template }}"
25+
nfc_pb_awx_tower_templates: "{{ nfc_pb_awx_tower_templates + job_template.vars.awx_tower_template }}"
2626
when: >
2727
job_template.vars | default({}) | length | int > 0
2828
and
@@ -36,18 +36,19 @@
3636
- name: Add Job template
3737
ansible.builtin.include_tasks:
3838
file: tasks/awx/job_template.yaml
39-
loop: "{{ awx_tower_templates }}"
39+
loop: "{{ nfc_pb_awx_tower_templates }}"
4040
loop_control:
41-
loop_var: awx_job_template
41+
loop_var: nfc_pb_awx_job_template
4242
when: >
4343
item.state == 'file'
4444
and
4545
'yaml' in item.path
4646
and
47-
item.path|basename|replace(".yaml","") not in awx_project.job_template_ignore | default([])
47+
item.path|basename|replace(".yaml","") not in nfc_pb_awx_project.job_template_ignore | default([])
4848
4949
5050
- name: Fact Cleanup - job_template
5151
ansible.builtin.set_fact:
52-
awx_tower_templates: []
53-
awx_playbook_filename:
52+
nfc_pb_awx_tower_templates: []
53+
nfc_pb_awx_playbook_filename:
54+
# nfc_pb_awx_job_template_name:

0 commit comments

Comments
 (0)