You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hetzner-ansible/roles/awx/tasks/awx-add-credential-to-job-t...

62 lines
1.8 KiB
YAML

---
- set_fact:
found_credential_id: ""
no_log: true
tags:
- awx_communication
- name: "Get {{jobinfo.name}} job_template credential id's from awx server"
uri:
url: "{{ awx_base_url }}/api/v2/job_templates/{{ awx_job_template_id }}/credentials"
method: GET
user: "{{ awx_rest_api_access_user }}"
password: "{{ awx_rest_api_access_pw }}"
return_content: true
validate_certs: false
force_basic_auth: yes
status_code: 200
no_log: true
register: awx_job_template_info
when: (awx_job_template_id | default("") | length > 0)
tags:
- awx_communication
- name: "Check for credential id {{ awx_credential_id }} in {{ jobinfo.name }} job_template"
vars:
query: '[? id==`{{ awx_credential_id }}`].id'
set_fact:
found_credential_id: "{{ item.results | json_query(query) | first }}"
when: >
(item.results is defined) and (item.results | length > 0) and
(item.results | json_query(query) | length > 0)
loop:
- "{{ awx_job_template_info['content'] }}"
no_log: true
tags:
- awx_communication
- name: "Add credential id {{ awx_credential_id }} to {{ jobinfo.name }} job_template"
uri:
url: "{{ awx_base_url }}/api/v2/job_templates/{{ awx_job_template_id }}/credentials/"
method: POST
user: "{{ awx_rest_api_access_user }}"
password: "{{ awx_rest_api_access_pw }}"
headers:
Content-Type: "application/json"
Accept: "application/json"
body_format: "json"
body: >
{
'associate': true,
'id': {{ awx_credential_id | int }}
}
force_basic_auth: true
validate_certs: false
status_code: 204
no_log: true
tags:
- awx_communication
when: >
(found_credential_id | default("") | length == 0) and
(awx_credential_id is defined) and
(awx_job_template_id | default("") | length > 0)