--- - set_fact: found_credential_id: "" 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 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'] }}" 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 tags: - awx_communication when: > (found_credential_id | default("") | length == 0) and (awx_credential_id is defined) and (awx_job_template_id | default("") | length > 0)