33echo " AAP - Automation controller Github Action"
44
55echo " CONTROLLER_HOST is $CONTROLLER_HOST "
6+ echo " JOB_TEMPLATE being executed $JOB_TEMPLATE "
7+ echo " CONTROLLER_VERIFY_SSL is set to $CONTROLLER_VERIFY_SSL "
68
79if [ -z " $CONTROLLER_HOST " ]; then
810 echo " Automation controller host is not set. Exiting."
@@ -19,7 +21,6 @@ if [ -z "$CONTROLLER_PASSWORD" ]; then
1921 exit 1
2022fi
2123
22- echo " JOB_TEMPLATE being executed $JOB_TEMPLATE "
2324
2425
2526tee ansible.cfg << EOF
@@ -38,20 +39,25 @@ tee playbook.yml << EOF
3839
3940 tasks:
4041
42+ - name: grab github action input
43+ set_fact:
44+ job_template_var: "$JOB_TEMPLATE "
45+ workflow_template_var: "$WORKFLOW_TEMPLATE "
46+ project_var: "$PROJECT "
47+
4148 - name: Launch a job template with extra_vars on remote controller instance
49+ when: job_template_var|length > 0
4250 awx.awx.job_launch:
43- job_template: "$JOB_TEMPLATE "
44- extra_vars:
45- your_region: "us-east-1"
46- var2: "My Second Variable"
47- var3: "My Third Variable"
51+ job_template: "{{ job_template_var }}"
52+ extra_vars: "$EXTRA_VARS "
4853 validate_certs: "$CONTROLLER_VERIFY_SSL "
4954 controller_username: "$CONTROLLER_USERNAME "
5055 controller_password: "$CONTROLLER_PASSWORD "
5156 controller_host: "$CONTROLLER_HOST "
5257 register: job_output
5358
5459 - name: Wait for job
60+ when: job_template_var|length > 0 or workflow_template_var|length > 0
5561 awx.awx.job_wait:
5662 job_id: "{{ job_output.id }}"
5763 timeout: 1800
@@ -61,6 +67,7 @@ tee playbook.yml << EOF
6167 controller_host: "$CONTROLLER_HOST "
6268
6369 - name: retrieve job info
70+ when: job_template_var|length > 0 or workflow_template_var|length > 0
6471 uri:
6572 url: https://$CONTROLLER_HOST /api/v2/jobs/{{ job_output.id }}/stdout/?format=json
6673 method: GET
@@ -70,7 +77,9 @@ tee playbook.yml << EOF
7077 force_basic_auth: yes
7178 register: playbook_output
7279
73- - debug:
80+ - name: display Automation controller job output
81+ when: job_template_var|length > 0 or workflow_template_var|length > 0
82+ debug:
7483 var: playbook_output.json.content
7584EOF
7685
@@ -79,9 +88,9 @@ echo "AAP Github Action - Executing Automation Job on Automation controller"
7988/usr/local/bin/ansible-playbook playbook.yml
8089
8190if [ $? -eq 0 ]; then
82- echo " Ansible Job has executed successfully"
91+ echo " Ansible Github Action Job has executed successfully"
8392else
84- echo " Ansible Job has failed"
93+ echo " Ansible Github Action Job has failed"
8594 exit 1
8695fi
8796
0 commit comments