Skip to content

Commit 346e1e2

Browse files
committed
syncing changes
1 parent dc63974 commit 346e1e2

File tree

2 files changed

+103
-37
lines changed

2 files changed

+103
-37
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
steps:
2424
- name: Load the ansible-cloud action
2525
id: controller_job
26-
uses: ansible-cloud/aap_controller_action@v1.2.26
26+
uses: ansible-cloud/aap_controller_action@v2.1.0
2727
with:
2828
controller_host: ${{ secrets.CONTROLLER_HOST }}
2929
controller_username: ${{ secrets.CONTROLLER_USERNAME }}

entrypoint.sh

Lines changed: 102 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,7 @@ tee playbook.yml << EOF
7676
set_fact:
7777
job_template_var: "$JOB_TEMPLATE"
7878
workflow_template_var: "$WORKFLOW_TEMPLATE"
79-
project_var: "$CONTROLLER_PROJECT"
8079
extra_vars: "$EXTRA_VARS"
81-
scm_url: "$scm_url"
82-
scm_branch: "$scm_branch"
83-
# scm_refspec: "$scm_refspec"
84-
scm_refspec: "refs/pull/*:refs/remotes/origin/pull/*"
8580
8681
- name: print out extra_vars
8782
debug:
@@ -92,7 +87,12 @@ tee playbook.yml << EOF
9287
block:
9388
- name: retrieve info on existing specified project in Automation controller
9489
set_fact:
95-
project_info: "{{ query('awx.awx.controller_api', 'projects', verify_ssl=$CONTROLLER_VERIFY_SSL, query_params={ 'name': 'test project' }) }}"
90+
project_info: "{{ query('awx.awx.controller_api', 'projects', verify_ssl=$CONTROLLER_VERIFY_SSL, query_params={ 'name': '$CONTROLLER_PROJECT' }) }}"
91+
template_info: "{{ query('awx.awx.controller_api', 'job_templates', verify_ssl=$CONTROLLER_VERIFY_SSL, query_params={ 'name': '$JOB_TEMPLATE' }) }}"
92+
scm_url: "$scm_url"
93+
scm_branch: "$scm_branch"
94+
scm_refspec: "$scm_refspec"
95+
project_var: "$CONTROLLER_PROJECT"
9696
9797
- name: print out existing project settings to terminal
9898
debug:
@@ -103,15 +103,61 @@ tee playbook.yml << EOF
103103
- scm_type: "{{ project_info[0].scm_type }}"
104104
- scm_url: "{{ project_info[0].scm_url }}"
105105
- scm_branch: "{{ project_info[0].scm_branch }}"
106-
- scm_refspec: "{{ project_info[0].scm_refspec }}"
106+
- scm_refspec: "refs/pull/*/head:refs/remotes/origin/pull/*"
107107
- credential: "{{ project_info[0].credential }}"
108108
- scm_clean: "{{ project_info[0].scm_clean }}"
109109
- scm_delete_on_update: "{{ project_info[0].scm_delete_on_update }}"
110110
- scm_track_submodules: "{{ project_info[0].scm_track_submodules }}"
111111
- scm_update_on_launch: "{{ project_info[0].scm_update_on_launch }}"
112112
- allow_override: "{{ project_info[0].allow_override }}"
113113
114-
- name: update project to point at pull request
114+
- name: print out existing job template settings to terminal
115+
debug:
116+
msg:
117+
- allow_simultaneous: "{{ template_info[0].allow_simultaneous }}"
118+
- ask_credential_on_launch: "{{ template_info[0].ask_credential_on_launch }}"
119+
- ask_diff_mode_on_launch: "{{ template_info[0].ask_diff_mode_on_launch }}"
120+
- ask_inventory_on_launch: "{{ template_info[0].ask_diff_mode_on_launch }}"
121+
- ask_job_type_on_launch: "{{ template_info[0].ask_job_type_on_launch }}"
122+
- ask_limit_on_launch: "{{ template_info[0].ask_limit_on_launch }}"
123+
- ask_scm_branch_on_launch: "{{ template_info[0].ask_scm_branch_on_launch }}"
124+
- ask_skip_tags_on_launch: "{{ template_info[0].ask_skip_tags_on_launch }}"
125+
- ask_tags_on_launch: "{{ template_info[0].ask_tags_on_launch }}"
126+
- ask_variables_on_launch: "{{ template_info[0].ask_variables_on_launch }}"
127+
- ask_verbosity_on_launch: "{{ template_info[0].ask_verbosity_on_launch }}"
128+
- become_enabled: "{{ template_info[0].become_enabled }}"
129+
- credentials: "{{ credentials | split(',') }}"
130+
- description: "{{ template_info[0].description }}"
131+
- diff_mode: "{{ template_info[0].diff_mode }}"
132+
- execution_environment: "{{ template_info[0].execution_environment }}"
133+
- extra_vars: "{% if not template_info[0].extra_vars | from_yaml %}{}{% else %}blah{% endif %}"
134+
- force_handlers: "{{ template_info[0].force_handlers }}"
135+
- forks: "{{ template_info[0].forks }}"
136+
- host_config_key: "{{ template_info[0].host_config_key }}"
137+
- inventory: "{{ template_info[0].inventory }}"
138+
- job_slice_count: "{{ template_info[0].job_slice_count }}"
139+
- job_tags: "{{ template_info[0].job_tags }}"
140+
- job_type: "{{ template_info[0].job_type }}"
141+
- limit: "{{ template_info[0].limit }}"
142+
- name: "{{ template_info[0].name }}"
143+
- organization: "{{ template_info[0].organization }}"
144+
- playbook: "{{ template_info[0].playbook }}"
145+
- project: "{{ template_info[0].project }}"
146+
- scm_branch: "{{ template_info[0].scm_branch }}"
147+
- skip_tags: "{{ template_info[0].skip_tags }}"
148+
- start_at_task: "{{ template_info[0].start_at_task }}"
149+
- survey_enabled: "{{ template_info[0].survey_enabled }}"
150+
- timeout: "{{ template_info[0].timeout }}"
151+
- use_fact_cache: "{{ template_info[0].use_fact_cache }}"
152+
- verbosity: "{{ template_info[0].verbosity }}"
153+
- wobhook_credential: "{{ template_info[0].webhook_credential | default(omit, true) }}"
154+
- webhook_service: "{{ template_info[0].webhook_service }}"
155+
156+
- name: figure out creds for JT
157+
set_fact:
158+
credentials: "{% for cred in template_info[0].summary_fields['credentials'] %}{{ cred.name }}{% if loop.length > 1 %},{% endif %}{% endfor %}"
159+
160+
- name: update project to allow scm allow_override and scm_update_on_launch
115161
awx.awx.project:
116162
name: "{{ project_var }}"
117163
state: present
@@ -121,28 +167,67 @@ tee playbook.yml << EOF
121167
scm_type: "{{ project_info[0].scm_type }}"
122168
scm_url: "$scm_url"
123169
scm_branch: "{{ project_info[0].scm_branch }}"
124-
scm_refspec: "{{ scm_refspec }}"
170+
scm_refspec: "$scm_refspec"
125171
# credential: "{{ project_info[0].credential }}"
126-
scm_clean: True
172+
scm_clean: "{{ project_info[0].scm_clean }}"
127173
scm_delete_on_update: "{{ project_info[0].scm_delete_on_update }}"
128174
scm_track_submodules: "{{ project_info[0].scm_track_submodules }}"
129-
scm_update_on_launch: "{{ project_info[0].scm_update_on_launch }}"
175+
scm_update_on_launch: True
130176
allow_override: True
177+
validate_certs: "$CONTROLLER_VERIFY_SSL"
131178
132-
- name: sync project update
133-
awx.awx.project_update:
134-
project: "{{ project_var }}"
179+
# This task is only updating ask_scm_branch_on_launch
180+
- name: update job template to turn ask_scm_branch_on_launch
181+
awx.awx.job_template:
182+
allow_simultaneous: "{{ template_info[0].allow_simultaneous }}"
183+
ask_credential_on_launch: "{{ template_info[0].ask_credential_on_launch }}"
184+
ask_diff_mode_on_launch: "{{ template_info[0].ask_diff_mode_on_launch }}"
185+
ask_inventory_on_launch: "{{ template_info[0].ask_diff_mode_on_launch }}"
186+
ask_job_type_on_launch: "{{ template_info[0].ask_job_type_on_launch }}"
187+
ask_limit_on_launch: "{{ template_info[0].ask_limit_on_launch }}"
188+
ask_scm_branch_on_launch: True
189+
ask_skip_tags_on_launch: "{{ template_info[0].ask_skip_tags_on_launch }}"
190+
ask_tags_on_launch: "{{ template_info[0].ask_tags_on_launch }}"
191+
ask_variables_on_launch: "{{ template_info[0].ask_variables_on_launch }}"
192+
ask_verbosity_on_launch: "{{ template_info[0].ask_verbosity_on_launch }}"
193+
become_enabled: "{{ template_info[0].become_enabled }}"
194+
credentials: "{{ credentials | split(',') }}"
195+
description: "{{ template_info[0].description }}"
196+
diff_mode: "{{ template_info[0].diff_mode }}"
197+
execution_environment: "{{ template_info[0].execution_environment }}"
198+
extra_vars: "{% if not template_info[0].extra_vars | from_yaml %}{}{% else %}blah{% endif %}"
199+
force_handlers: "{{ template_info[0].force_handlers }}"
200+
forks: "{{ template_info[0].forks }}"
201+
host_config_key: "{{ template_info[0].host_config_key }}"
202+
inventory: "{{ template_info[0].inventory }}"
203+
job_slice_count: "{{ template_info[0].job_slice_count }}"
204+
job_tags: "{{ template_info[0].job_tags }}"
205+
job_type: "{{ template_info[0].job_type }}"
206+
limit: "{{ template_info[0].limit }}"
207+
name: "{{ template_info[0].name }}"
208+
organization: "{{ template_info[0].organization }}"
209+
playbook: "{{ template_info[0].playbook }}"
210+
project: "{{ template_info[0].project }}"
211+
scm_branch: "{{ template_info[0].scm_branch }}"
212+
skip_tags: "{{ template_info[0].skip_tags }}"
213+
start_at_task: "{{ template_info[0].start_at_task }}"
214+
survey_enabled: "{{ template_info[0].survey_enabled }}"
215+
timeout: "{{ template_info[0].timeout }}"
216+
use_fact_cache: "{{ template_info[0].use_fact_cache }}"
217+
verbosity: "{{ template_info[0].verbosity }}"
218+
webhook_credential: "{{ template_info[0].webhook_credential | default(omit, true) }}"
219+
webhook_service: "{{ template_info[0].webhook_service }}"
135220
validate_certs: "$CONTROLLER_VERIFY_SSL"
136-
wait: true
221+
137222
when: project_var|length > 0
138223
139-
- name: Launch a job template with extra_vars on remote controller instance
224+
- name: Launch a job template with extra_vars on remote controller instance when project is set
140225
when: job_template_var|length > 0
141226
awx.awx.job_launch:
142227
job_template: "{{ job_template_var }}"
143228
extra_vars: "$EXTRA_VARS"
144229
validate_certs: "$CONTROLLER_VERIFY_SSL"
145-
scm_branch: "{{ scm_branch }}"
230+
scm_branch: "{{ scm_branch | default(omit, true) }}"
146231
register: job_output
147232
148233
- name: Wait for job
@@ -174,25 +259,6 @@ tee playbook.yml << EOF
174259
content: "{{ playbook_output.json.content }}"
175260
dest: job_output.txt
176261
177-
# - name: revert project settings back to original
178-
# awx.awx.project:
179-
# name: "{{ project_var }}"
180-
# state: present
181-
# description: "{{ project_info[0].description }}"
182-
# organization: "{{ project_info[0].organization }}"
183-
# default_environment: "{{ project_info[0].default_environment }}"
184-
# scm_type: "{{ project_info[0].scm_type }}"
185-
# scm_url: "{{ project_info[0].scm_url }}"
186-
# scm_branch: "{{ project_info[0].scm_branch }}"
187-
# scm_refspec: "{{ project_info[0].scm_refspec }}"
188-
# # credential: "{{ project_info[0].credential }}"
189-
# scm_clean: "{{ project_info[0].scm_clean }}"
190-
# scm_delete_on_update: "{{ project_info[0].scm_delete_on_update }}"
191-
# scm_track_submodules: "{{ project_info[0].scm_track_submodules }}"
192-
# scm_update_on_launch: "{{ project_info[0].scm_update_on_launch }}"
193-
# allow_override: "{{ project_info[0].allow_override }}"
194-
# when: project_var|length > 0
195-
196262
EOF
197263

198264
echo "AAP Github Action - Executing Automation Job on Automation controller"

0 commit comments

Comments
 (0)