Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Custom Credentials to be associated with job templates. #13

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ tower_config:
forks: 50
limit: "dev"
credential: "network-nxos-ssh, network-nxos-net"
associated_credentials:
- name: empty-scm
state: present
- name: "Dev: devops:helloworld"
description: "Dev: devops:helloworld"
project: "Dev: netops:ansible-tower-example"
Expand Down
3 changes: 3 additions & 0 deletions molecule/default/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@
limit: "dev"
machine_credential: "network-nxos-ssh"
network_credential: "network-nxos-net"
associated_credentials:
- name: "empty-scm"
state: present
- name: "Dev: devops:helloworld"
description: "Dev: devops:helloworld"
project: "Dev: devops:ansible-tower-example"
Expand Down
115 changes: 12 additions & 103 deletions tasks/config/organization/credential_type.yml
Original file line number Diff line number Diff line change
@@ -1,105 +1,14 @@
---
- name: "config.organization.credential_type: [ {{ tower_config_organization_credential_type.name }} ]"
vars:
url_host: "https://{{ tower_config.host }}"
url_api: "/api/v2/credential_types/"
user: "{{ tower_config.username }}"
password: "{{ tower_config.password }}"
validate_certs: "{{ tower_config.verify_ssl | default(omit) }}"
force_basic_auth: true
headers:
Content-Type: "application/json"
Accept: "application/json"
body:
name: "{{ tower_config_organization_credential_type.name | mandatory }}"
description: "{{ tower_config_organization_credential_type.name | default('') }}"
kind: "{{ tower_config_organization_credential_type.kind | default('cloud') }}"
inputs: "{{ tower_config_organization_credential_type.inputs | mandatory }}"
injectors: "{{ tower_config_organization_credential_type.injectors | mandatory }}"
body_format: "{{ tower_config.format }}"

block:
- when: "tower_config_organization_credential_type.state|default('present') == 'present'"
block:
- vars:
a: "{{ url_host }}"
b: "{{ url_api }}"
c: "{{ tower_config_organization_credential_type.name }}"
d: "{{ tower_config_organization_credential_type.kind | default('cloud') }}"
uri:
method: GET
url: "{{ a }}{{ b }}{{ c }}+{{ d }}"
user: "{{ user }}"
password: "{{ password }}"
validate_certs: "{{ validate_certs }}"
force_basic_auth: true
headers: "{{ headers }}"
body_format: "{{ body_format }}"
register: reg_credential_type

rescue:
- uri:
method: POST
url: "{{ url_host }}{{ url_api }}"
user: "{{ user }}"
password: "{{ password }}"
validate_certs: "{{ validate_certs }}"
force_basic_auth: true
headers: "{{ headers }}"
body_format: "{{ body_format }}"
register: reg_credential_type

always:
- uri:
method: PATCH
url: "https://{{ tower_config.host }}/{{ reg_credential_type.json.url }}"
user: "{{ tower_config.username }}"
password: "{{ tower_config.password }}"
validate_certs: "{{ tower_config.verify_ssl|bool }}"
force_basic_auth: true
headers: "{{ headers }}"
body: "{{ body }}"
body_format: "{{ tower_config.format }}"
register: reg_credential_type
- when: "tower_config_organization_credential_type.state|default('present') == 'absent'"
block:
- vars:
a: "{{ url_host }}"
b: "{{ url_api }}"
c: "{{ tower_config_organization_credential_type.name }}"
d: "{{ tower_config_organization_credential_type.kind | default('cloud') }}"
uri:
method: GET
url: "{{ a }}{{ b }}{{ c }}+{{ d }}"
user: "{{ user }}"
password: "{{ password }}"
validate_certs: "{{ validate_certs }}"
force_basic_auth: true
headers: "{{ headers }}"
body_format: "{{ body_format }}"
register: reg_credential_type

rescue:
- uri:
method: POST
url: "{{ url_host }}{{ url_api }}"
user: "{{ user }}"
password: "{{ password }}"
validate_certs: "{{ validate_certs }}"
force_basic_auth: true
headers: "{{ headers }}"
body_format: "{{ body_format }}"
register: reg_credential_type

always:
- uri:
method: PATCH
url: "https://{{ tower_config.host }}/{{ reg_credential_type.json.url }}"
user: "{{ tower_config.username }}"
password: "{{ tower_config.password }}"
validate_certs: "{{ tower_config.verify_ssl|bool }}"
force_basic_auth: true
headers: "{{ headers }}"
body: "{{ body }}"
body_format: "{{ tower_config.format }}"
register: reg_credential_type
- name: "config.organization.credential_type: [ {{ tower_config_organization_credential_type.name }} ]"
tower_credential_type:
tower_host: "{{ tower_config.host | default(omit) }}"
tower_username: "{{ tower_config.username | default(omit) }}"
tower_password: "{{ tower_config.password | default(omit) }}"
tower_verify_ssl: "{{ tower_config.verify_ssl | default(omit) }}"
description: "{{ tower_config_organization_credential_type.description | default(omit) }}"
injectors: "{{ tower_config_organization_credential_type.injectors | default(omit) | to_json }}"
inputs: "{{ tower_config_organization_credential_type.inputs | default(omit) }}"
kind: "{{ tower_config_organization_credential_type.kind | default(omit) }}"
name: "{{ tower_config_organization_credential_type.name }}"
state: "{{ tower_config_organization_credential_type.state | default(omit) }}"
2 changes: 0 additions & 2 deletions tasks/config/organization/inventory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@
loop_control:
loop_var: tower_config_organization_inventory_source
label: "{{ tower_config_organization_inventory_source.name }}"
async: 15
poll: 1
7 changes: 7 additions & 0 deletions tasks/config/organization/job_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@
state: "{{ tower_config_organization_job_template.state | default(omit) }}"
async: 15
poll: 1

- name: "config.organization.job_template.associate_credentials: [ {{ tower_config_organization_job_template.name }} ]"
command: "{{ lookup('template', 'job-template-credential-association-cli.j2') }}"
loop: "{{ tower_config_organization_job_template.associate_credentials | default ([]) }}"
loop_control:
loop_var: tower_config_organization_job_template_credential
label: "{{ tower_config_organization_job_template.name }}"
8 changes: 8 additions & 0 deletions tasks/config/organization/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
loop_var: tower_config_organization_team
label: "{{ tower_config_organization_team.name }}"

- name: "config.organization: Process [ credential_types ]"
when: tower_config_organization.credential_types is defined
include_tasks: "credential_type.yml"
loop: "{{ tower_config_organization.credential_types | default ([]) }}"
loop_control:
loop_var: tower_config_organization_credential_type
label: "{{ tower_config_organization_credential_type.name }}"

- name: "config.organization: Process [ credentials ]"
when: tower_config_organization.credentials is defined
include_tasks: "credential.yml"
Expand Down
2 changes: 0 additions & 2 deletions tasks/config/organization/team.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,3 @@
loop_control:
loop_var: tower_config_organization_team_member
label: "{{ tower_config_organization_team_member.name }}"
async: 15
poll: 1
11 changes: 11 additions & 0 deletions templates/job-template-credential-association-cli.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
tower-cli
job_template
{% if tower_config_organization_job_template_credential.state|default('present') == 'present' %}
associate_credential
{% elif tower_config_organization_job_template_credential.state|default('present') == 'absent' %}
disassociate_credential
{% endif %}
{% if tower_config_organization_job_template.name is defined %}
--job-template {{ tower_config_organization_job_template.name | quote }}
{% endif %}
--credential {{ tower_config_organization_job_template_credential.name | quote }}