Skip to content

Commit a30eb34

Browse files
committed
v1.2.23
1 parent c6e0e37 commit a30eb34

File tree

4 files changed

+245
-30
lines changed

4 files changed

+245
-30
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/[email protected].22
26+
uses: ansible-cloud/[email protected].23
2727
with:
2828
controller_host: ${{ secrets.CONTROLLER_HOST }}
2929
controller_username: ${{ secrets.CONTROLLER_USERNAME }}

entrypoint.sh

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ echo "scm_url is $scm_url"
5050
scm_branch="pull/$pull_request_event/head"
5151
echo "scm_branch is $scm_branch"
5252

53-
scm_refspec="refs/pull/$pull_request_event/head:refs/remotes/origin/pull/$pull_request_event/head"
54-
echo "scm_refspec is $scm_refspec"
53+
# scm_refspec="refs/pull/$pull_request_event/head:refs/remotes/origin/pull/$pull_request_event/head"
54+
# echo "scm_refspec is $scm_refspec"
5555

5656

5757

@@ -102,7 +102,7 @@ tee playbook.yml << EOF
102102
- scm_type: "{{ project_info[0].scm_type }}"
103103
- scm_url: "{{ project_info[0].scm_url }}"
104104
- scm_branch: "{{ project_info[0].scm_branch }}"
105-
- scm_refspec: "{{ project_info[0].scm_refspec }}"
105+
- scm_refspec: "refs/pull/*/head:refs/remotes/origin/pull/*"
106106
- credential: "{{ project_info[0].credential }}"
107107
- scm_clean: "{{ project_info[0].scm_clean }}"
108108
- scm_delete_on_update: "{{ project_info[0].scm_delete_on_update }}"
@@ -119,18 +119,19 @@ tee playbook.yml << EOF
119119
default_environment: "{{ project_info[0].default_environment }}"
120120
scm_type: "{{ project_info[0].scm_type }}"
121121
scm_url: "$scm_url"
122-
scm_branch: "$scm_branch"
122+
scm_branch: "{{ project_info[0].scm_branch }}"
123123
scm_refspec: "$scm_refspec"
124124
# credential: "{{ project_info[0].credential }}"
125125
scm_clean: "{{ project_info[0].scm_clean }}"
126126
scm_delete_on_update: "{{ project_info[0].scm_delete_on_update }}"
127127
scm_track_submodules: "{{ project_info[0].scm_track_submodules }}"
128128
scm_update_on_launch: "{{ project_info[0].scm_update_on_launch }}"
129-
allow_override: "{{ project_info[0].allow_override }}"
129+
allow_override: True
130130
131131
- name: sync project update
132132
awx.awx.project_update:
133133
project: "{{ project_var }}"
134+
validate_certs: "$CONTROLLER_VERIFY_SSL"
134135
wait: true
135136
when: project_var|length > 0
136137
@@ -140,9 +141,7 @@ tee playbook.yml << EOF
140141
job_template: "{{ job_template_var }}"
141142
extra_vars: "$EXTRA_VARS"
142143
validate_certs: "$CONTROLLER_VERIFY_SSL"
143-
controller_username: "$CONTROLLER_USERNAME"
144-
controller_password: "$CONTROLLER_PASSWORD"
145-
controller_host: "$CONTROLLER_HOST"
144+
scm_branch: "{{ scm_branch }}"
146145
register: job_output
147146
148147
- name: Wait for job
@@ -151,9 +150,6 @@ tee playbook.yml << EOF
151150
job_id: "{{ job_output.id }}"
152151
timeout: 3600
153152
validate_certs: "$CONTROLLER_VERIFY_SSL"
154-
controller_username: "$CONTROLLER_USERNAME"
155-
controller_password: "$CONTROLLER_PASSWORD"
156-
controller_host: "$CONTROLLER_HOST"
157153
158154
- name: retrieve job info
159155
when: job_template_var|length > 0 or workflow_template_var|length > 0
@@ -177,24 +173,24 @@ tee playbook.yml << EOF
177173
content: "{{ playbook_output.json.content }}"
178174
dest: job_output.txt
179175
180-
- name: revert project settings back to original
181-
awx.awx.project:
182-
name: "{{ project_var }}"
183-
state: present
184-
description: "{{ project_info[0].description }}"
185-
organization: "{{ project_info[0].organization }}"
186-
default_environment: "{{ project_info[0].default_environment }}"
187-
scm_type: "{{ project_info[0].scm_type }}"
188-
scm_url: "{{ project_info[0].scm_url }}"
189-
scm_branch: "{{ project_info[0].scm_branch }}"
190-
scm_refspec: "{{ project_info[0].scm_refspec }}"
191-
# credential: "{{ project_info[0].credential }}"
192-
scm_clean: "{{ project_info[0].scm_clean }}"
193-
scm_delete_on_update: "{{ project_info[0].scm_delete_on_update }}"
194-
scm_track_submodules: "{{ project_info[0].scm_track_submodules }}"
195-
scm_update_on_launch: "{{ project_info[0].scm_update_on_launch }}"
196-
allow_override: "{{ project_info[0].allow_override }}"
197-
when: project_var|length > 0
176+
# - name: revert project settings back to original
177+
# awx.awx.project:
178+
# name: "{{ project_var }}"
179+
# state: present
180+
# description: "{{ project_info[0].description }}"
181+
# organization: "{{ project_info[0].organization }}"
182+
# default_environment: "{{ project_info[0].default_environment }}"
183+
# scm_type: "{{ project_info[0].scm_type }}"
184+
# scm_url: "{{ project_info[0].scm_url }}"
185+
# scm_branch: "{{ project_info[0].scm_branch }}"
186+
# scm_refspec: "{{ project_info[0].scm_refspec }}"
187+
# # credential: "{{ project_info[0].credential }}"
188+
# scm_clean: "{{ project_info[0].scm_clean }}"
189+
# scm_delete_on_update: "{{ project_info[0].scm_delete_on_update }}"
190+
# scm_track_submodules: "{{ project_info[0].scm_track_submodules }}"
191+
# scm_update_on_launch: "{{ project_info[0].scm_update_on_launch }}"
192+
# allow_override: "{{ project_info[0].allow_override }}"
193+
# when: project_var|length > 0
198194
199195
EOF
200196

entrypoint.sh.bak

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
#! /usr/bin/bash
2+
# PY_COLORS: '1'
3+
# ANSIBLE_FORCE_COLOR: '1'
4+
5+
export PY_COLORS=1
6+
export ANSIBLE_FORCE_COLOR=1
7+
8+
echo "AAP - Automation controller Github Action"
9+
10+
if [ -z "$CONTROLLER_HOST" ]; then
11+
echo "Automation controller host is not set. Exiting."
12+
exit 1
13+
fi
14+
15+
if [ -z "$CONTROLLER_USERNAME" ]; then
16+
echo "Automation controller username is not set. Exiting."
17+
exit 1
18+
fi
19+
20+
if [ -z "$CONTROLLER_PASSWORD" ]; then
21+
echo "Automation controller password is not set. Exiting."
22+
exit 1
23+
fi
24+
25+
echo "CONTROLLER_HOST is $CONTROLLER_HOST"
26+
echo "JOB_TEMPLATE being executed $JOB_TEMPLATE"
27+
echo "EXTRA_VARS is set to $EXTRA_VARS"
28+
echo "CONTROLLER_VERIFY_SSL is set to $CONTROLLER_VERIFY_SSL"
29+
echo "CONTROLLER_PROJECT is set to $CONTROLLER_PROJECT"
30+
echo "----------------"
31+
echo "GITHUB_BASE_REF is $GITHUB_BASE_REF"
32+
echo "GITHUB_HEAD_REF is $GITHUB_HEAD_REF"
33+
echo "GITHUB_REF_NAME is $GITHUB_REF_NAME"
34+
echo "GITHUB_EVENT_NAME is $GITHUB_EVENT_NAME"
35+
echo "GITHUB_JOB is $GITHUB_JOB"
36+
echo "GITHUB_REF is $GITHUB_REF"
37+
echo "GITHUB_REPOSITORY is $GITHUB_REPOSITORY"
38+
echo "pull_request_event is $pull_request_event"
39+
echo "---------------"
40+
41+
pull/1/head
42+
43+
# scm_url e.g. https://github.com/ansible-cloud/aap_controller_action
44+
# scm_branch e.g. pull/1/head (for PR #1)
45+
# scm_refspec e.g. refs/pull/1/head:refs/remotes/origin/pull/1/head
46+
47+
scm_url="https://github.com/$GITHUB_REPOSITORY"
48+
echo "scm_url is $scm_url"
49+
50+
scm_branch="pull/$pull_request_event/head"
51+
echo "scm_branch is $scm_branch"
52+
53+
scm_refspec="refs/pull/$pull_request_event/head:refs/remotes/origin/pull/$pull_request_event/head"
54+
echo "scm_refspec is $scm_refspec"
55+
56+
57+
58+
tee ansible.cfg << EOF
59+
[defaults]
60+
COLLECTIONS_PATHS = /root/.ansible/collections
61+
stdout_callback=community.general.yaml
62+
callbacks_enabled=ansible.posix.profile_tasks
63+
64+
EOF
65+
66+
67+
tee playbook.yml << EOF
68+
---
69+
- name: execute autmation job
70+
hosts: localhost
71+
gather_facts: no
72+
73+
tasks:
74+
75+
- name: grab github action input
76+
set_fact:
77+
job_template_var: "$JOB_TEMPLATE"
78+
workflow_template_var: "$WORKFLOW_TEMPLATE"
79+
project_var: "$CONTROLLER_PROJECT"
80+
extra_vars: "$EXTRA_VARS"
81+
scm_url: "$scm_url"
82+
scm_branch: "$scm_branch"
83+
scm_refspec: "$scm_refspec"
84+
85+
- name: print out extra_vars
86+
debug:
87+
msg:
88+
- "extra vars are {{ extra_vars }}"
89+
90+
- name: project update and sync
91+
block:
92+
- name: retrieve info on existing specified project in Automation controller
93+
set_fact:
94+
project_info: "{{ query('awx.awx.controller_api', 'projects', verify_ssl=$CONTROLLER_VERIFY_SSL, query_params={ 'name': 'test project' }) }}"
95+
96+
- name: print out existing project settings to terminal
97+
debug:
98+
msg:
99+
- description: "{{ project_info[0].description }}"
100+
- organization: "{{ project_info[0].organization }}"
101+
- default_environment: "{{ project_info[0].default_environment }}"
102+
- scm_type: "{{ project_info[0].scm_type }}"
103+
- scm_url: "{{ project_info[0].scm_url }}"
104+
- scm_branch: "{{ project_info[0].scm_branch }}"
105+
- scm_refspec: "{{ project_info[0].scm_refspec }}"
106+
- credential: "{{ project_info[0].credential }}"
107+
- scm_clean: "{{ project_info[0].scm_clean }}"
108+
- scm_delete_on_update: "{{ project_info[0].scm_delete_on_update }}"
109+
- scm_track_submodules: "{{ project_info[0].scm_track_submodules }}"
110+
- scm_update_on_launch: "{{ project_info[0].scm_update_on_launch }}"
111+
- allow_override: "{{ project_info[0].allow_override }}"
112+
113+
- name: update project to point at pull request
114+
awx.awx.project:
115+
name: "{{ project_var }}"
116+
state: present
117+
description: "{{ project_info[0].description }}"
118+
organization: "{{ project_info[0].organization }}"
119+
default_environment: "{{ project_info[0].default_environment }}"
120+
scm_type: "{{ project_info[0].scm_type }}"
121+
scm_url: "$scm_url"
122+
scm_branch: "$scm_branch"
123+
scm_refspec: "$scm_refspec"
124+
# credential: "{{ project_info[0].credential }}"
125+
scm_clean: "{{ project_info[0].scm_clean }}"
126+
scm_delete_on_update: "{{ project_info[0].scm_delete_on_update }}"
127+
scm_track_submodules: "{{ project_info[0].scm_track_submodules }}"
128+
scm_update_on_launch: "{{ project_info[0].scm_update_on_launch }}"
129+
allow_override: "{{ project_info[0].allow_override }}"
130+
131+
- name: sync project update
132+
awx.awx.project_update:
133+
project: "{{ project_var }}"
134+
wait: true
135+
when: project_var|length > 0
136+
137+
- name: Launch a job template with extra_vars on remote controller instance
138+
when: job_template_var|length > 0
139+
awx.awx.job_launch:
140+
job_template: "{{ job_template_var }}"
141+
extra_vars: "$EXTRA_VARS"
142+
validate_certs: "$CONTROLLER_VERIFY_SSL"
143+
controller_username: "$CONTROLLER_USERNAME"
144+
controller_password: "$CONTROLLER_PASSWORD"
145+
controller_host: "$CONTROLLER_HOST"
146+
register: job_output
147+
148+
- name: Wait for job
149+
when: job_template_var|length > 0 or workflow_template_var|length > 0
150+
awx.awx.job_wait:
151+
job_id: "{{ job_output.id }}"
152+
timeout: 3600
153+
validate_certs: "$CONTROLLER_VERIFY_SSL"
154+
controller_username: "$CONTROLLER_USERNAME"
155+
controller_password: "$CONTROLLER_PASSWORD"
156+
controller_host: "$CONTROLLER_HOST"
157+
158+
- name: retrieve job info
159+
when: job_template_var|length > 0 or workflow_template_var|length > 0
160+
uri:
161+
url: https://$CONTROLLER_HOST/api/v2/jobs/{{ job_output.id }}/stdout/?format=json
162+
method: GET
163+
user: "$CONTROLLER_USERNAME"
164+
password: "$CONTROLLER_PASSWORD"
165+
validate_certs: "$CONTROLLER_VERIFY_SSL"
166+
force_basic_auth: yes
167+
register: playbook_output
168+
169+
- name: display Automation controller job output
170+
when: job_template_var|length > 0 or workflow_template_var|length > 0
171+
debug:
172+
var: playbook_output.json.content
173+
174+
- name: copy playbook output from Automation controller to file
175+
when: job_template_var|length > 0 or workflow_template_var|length > 0
176+
ansible.builtin.copy:
177+
content: "{{ playbook_output.json.content }}"
178+
dest: job_output.txt
179+
180+
- name: revert project settings back to original
181+
awx.awx.project:
182+
name: "{{ project_var }}"
183+
state: present
184+
description: "{{ project_info[0].description }}"
185+
organization: "{{ project_info[0].organization }}"
186+
default_environment: "{{ project_info[0].default_environment }}"
187+
scm_type: "{{ project_info[0].scm_type }}"
188+
scm_url: "{{ project_info[0].scm_url }}"
189+
scm_branch: "{{ project_info[0].scm_branch }}"
190+
scm_refspec: "{{ project_info[0].scm_refspec }}"
191+
# credential: "{{ project_info[0].credential }}"
192+
scm_clean: "{{ project_info[0].scm_clean }}"
193+
scm_delete_on_update: "{{ project_info[0].scm_delete_on_update }}"
194+
scm_track_submodules: "{{ project_info[0].scm_track_submodules }}"
195+
scm_update_on_launch: "{{ project_info[0].scm_update_on_launch }}"
196+
allow_override: "{{ project_info[0].allow_override }}"
197+
when: project_var|length > 0
198+
199+
EOF
200+
201+
echo "AAP Github Action - Executing Automation Job on Automation controller"
202+
203+
/usr/local/bin/ansible-playbook playbook.yml
204+
205+
if [ $? -eq 0 ]; then
206+
echo "Ansible Github Action Job has executed successfully"
207+
else
208+
echo "Ansible Github Action Job has failed"
209+
exit 1
210+
fi
211+
212+
echo "END OF AAP - Automation controller Github Action"

playbooks/dummy.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
- hosts: localhost
3+
gather_facts: true
4+
tasks:
5+
- name: print host vars for localhost
6+
debug:
7+
var: hostvars["{{ ansible_host }}"]

0 commit comments

Comments
 (0)