Skip to content

Commit 9f5390d

Browse files
committed
feat(awx): inventory and inventory sources now configurable
!28
1 parent 042ca62 commit 9f5390d

File tree

3 files changed

+51
-45
lines changed

3 files changed

+51
-45
lines changed

tasks/awx/inventory.yaml

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,73 @@
11
---
22
- name: Add inventory
33
awx.awx.inventory:
4-
name: "Production"
5-
description: "{{ nfc_pb_awx_inventory.description | default('') }}"
64
controller_host: "{{ nfc_pb_awx_controller_host | default(omit) }}"
75
controller_oauthtoken: "{{ nfc_pb_awx_controller_oauthtoken | default(omit) }}"
86
controller_username: "{{ nfc_pb_awx_controller_username | default(omit) }}"
97
controller_password: "{{ nfc_pb_awx_controller_password | default(omit) }}"
108
organization: "{{ nfc_pb_awx_organization.name }}"
11-
state: present
129
validate_certs: "{{ validate_certs | default(true) }}"
10+
11+
name: "{{ nfc_pb_awx_inventory.name }}"
12+
description: "{{ nfc_pb_awx_inventory.description | default('') }}"
13+
host_filter: "{{ nfc_pb_awx_inventory.host_filter | default('') }}"
14+
instance_groups: "{{ nfc_pb_awx_inventory.instance_groups | default([]) }}"
15+
prevent_instance_group_fallback: "{{ nfc_pb_awx_inventory.prevent_instance_group_fallback | default(false) | bool }}"
16+
state: "{{ nfc_pb_awx_inventory.state | default('present') }}"
17+
kind: "{{ nfc_pb_awx_inventory.kind | default(omit) }}"
1318
# no_log: true
1419
diff: true
1520

1621

1722
- name: Add an inventory source
1823
awx.awx.inventory_source:
19-
name: "{{ nfc_pb_awx_project.name }}"
20-
description: "{{ nfc_pb_awx_inventory.description | default('') }}"
2124
controller_host: "{{ nfc_pb_awx_controller_host | default(omit) }}"
2225
controller_oauthtoken: "{{ nfc_pb_awx_controller_oauthtoken | default(omit) }}"
2326
controller_username: "{{ nfc_pb_awx_controller_username | default(omit) }}"
2427
controller_password: "{{ nfc_pb_awx_controller_password | default(omit) }}"
2528
validate_certs: "{{ validate_certs | default(true) }}"
29+
2630
organization: "{{ nfc_pb_awx_organization.name }}"
27-
inventory: "Production"
31+
source_project: "{{ nfc_pb_awx_project.name }}"
32+
inventory: "{{ nfc_pb_awx_inventory.name }}"
33+
name: "{{ nfc_pb_awx_inventory_source.name }}"
34+
description: "{{ nfc_pb_awx_inventory_source.description | default('') }}"
35+
2836
# credential: previously-created-credential
2937
# overwrite: True
3038
# update_on_launch: True
31-
source_project: "{{ nfc_pb_awx_project.name }}"
32-
source_path: inventory/production/
33-
source: scm
34-
state: present
35-
verbosity: 2
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) }}"
39+
40+
source_path: "{{ nfc_pb_awx_inventory_source.source_path | default(omit) }}"
41+
source: "{{ nfc_pb_awx_inventory_source.source | default('scm') }}"
42+
state: "{{ nfc_pb_awx_inventory_source.state | default('present') }}"
43+
overwrite: "{{ nfc_pb_awx_inventory_source.overwrite | default(true) | bool }}"
44+
overwrite_vars: "{{ nfc_pb_awx_inventory_source.overwrite_vars | default(true) | bool }}"
45+
scm_branch: >-
46+
{%- if nfc_pb_awx_project.scm_branch_allow_override | default(false) | bool -%}
47+
{{ nfc_pb_awx_inventory_source.scm_branch | default(nfc_pb_awx_project.scm_branch) }}
48+
{%- else -%}
49+
{{ omit }}
50+
{%- endif %}
51+
verbosity: "{{ nfc_pb_awx_inventory_source.verbosity | default(0) | int }}"
3952
# no_log: true
4053
diff: true
54+
loop: "{{ nfc_pb_awx_inventory.sources | default([]) | list }}"
55+
loop_control:
56+
loop_var: nfc_pb_awx_inventory_source
4157

4258

43-
- name: "Update inventory sources {{ nfc_pb_awx_project.name }}/{{ nfc_pb_awx_project.name }}"
44-
awx.awx.inventory_source_update:
45-
name: "{{ nfc_pb_awx_project.name }}"
46-
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 }}"
52-
validate_certs: "{{ validate_certs | default(true) }}"
53-
# no_log: true
54-
diff: true
59+
# - name: "Update inventory sources {{ nfc_pb_awx_project.name }}/{{ nfc_pb_awx_project.name }}"
60+
# awx.awx.inventory_source_update:
61+
# name: "{{ nfc_pb_awx_project.name }}"
62+
# inventory: "Production"
63+
# controller_host: "{{ nfc_pb_awx_controller_host | default(omit) }}"
64+
# controller_oauthtoken: "{{ nfc_pb_awx_controller_oauthtoken | default(omit) }}"
65+
# controller_username: "{{ nfc_pb_awx_controller_username | default(omit) }}"
66+
# controller_password: "{{ nfc_pb_awx_controller_password | default(omit) }}"
67+
# organization: "{{ nfc_pb_awx_organization.name }}"
68+
# validate_certs: "{{ validate_certs | default(true) }}"
69+
# # no_log: true
70+
# diff: true
5571

5672

5773
- name: "RBAC - {{ nfc_pb_awx_organization.name }}/Project/{{ nfc_pb_awx_project.name }}/Inventory"

tasks/awx/job_template.yaml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
organization: "{{ nfc_pb_awx_organization.name }}"
5656
# inventory: "{{ nfc_pb_awx_inventory.name | default(omit) }}"
5757
project: "{{ nfc_pb_awx_project.name }}"
58-
playbook: "{{ nfc_pb_awx_project.path | default('') }}{{ nfc_pb_awx_playbook_filename }}"
58+
playbook: "{{ nfc_pb_awx_project.playbook_path | default('') }}{{ nfc_pb_awx_playbook_filename }}"
5959
# scm_branch: "{{ nfc_pb_awx_branch }}"
6060
ask_tags_on_launch: "{{ nfc_pb_awx_job_template.ask_tags_on_launch | default(false) | bool }}"
6161
ask_inventory_on_launch: "{{ nfc_pb_awx_job_template.ask_inventory_on_launch | default(true) | bool }}"
@@ -89,12 +89,7 @@
8989
loop: "{{ nfc_pb_awx_project.rbac.job }}"
9090
loop_control:
9191
loop_var: nfc_pb_awx_rbac
92-
when:
93-
(
94-
nfc_pb_awx_project.type | lower == 'playbook'
95-
or
96-
nfc_pb_awx_project.type | lower == 'both'
97-
)
92+
when: nfc_pb_awx_project.playbook_path | default('') != ''
9893
vars:
9994
nfc_pb_awx_job_template_name: "{{ nfc_pb_awx_job_template.name }}"
10095

tasks/awx/project.yaml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,10 @@
4141
- name: "Inventory - {{ nfc_pb_awx_organization.name }}/Project/{{ nfc_pb_awx_project.name }}"
4242
ansible.builtin.include_tasks:
4343
file: tasks/awx/inventory.yaml
44-
when: >
45-
(
46-
nfc_pb_awx_project.type | lower == 'inventory'
47-
or
48-
nfc_pb_awx_project.type | lower == 'both'
49-
)
44+
loop: "{{ nfc_pb_awx_project.inventories | default([]) | list }}"
45+
loop_control:
46+
loop_var: nfc_pb_awx_inventory
47+
5048

5149
# - name: GIT Checkout Project
5250
# ansible.builtin.git:
@@ -72,24 +70,21 @@
7270
# # depth: 1
7371
# version: "{{ nfc_pb_awx_project.scm_branch | default('master') }}"
7472
# # single_branch: true
75-
when: >
76-
nfc_pb_awx_project.scm_url | default('') != ''
77-
and
78-
nfc_pb_awx_project.type | lower == 'playbook'
73+
when: nfc_pb_awx_project.playbook_path is defined
7974

8075

8176
- name: Add Job templates
8277
ansible.builtin.include_tasks:
8378
file: tasks/awx/job_templates.yaml
84-
loop: "{{ lookup('community.general.filetree', '/tmp/project/' + path | default('')) }}"
79+
loop: "{{ lookup('community.general.filetree', '/tmp/project/' + nfc_pb_awx_project.playbook_path | default('')) }}"
8580
when: >
8681
item.state == 'file'
8782
and
8883
'yaml' in item.path
8984
and
9085
item.path|basename|replace(".yaml","") not in nfc_pb_awx_project.job_template_ignore | default([])
9186
and
92-
nfc_pb_awx_project.type | lower == 'playbook'
87+
nfc_pb_awx_project.playbook_path is defined
9388
vars:
9489
nfc_pb_awx_playbook_filename: "{{ item.path }}"
9590
nfc_pb_awx_playbook_dir: "{{ item.root }}"

0 commit comments

Comments
 (0)