Initial commit

This commit is contained in:
Jon Ervine
2021-03-02 20:53:43 +08:00
parent 89d3a2dfe1
commit f961b728fa
2919 changed files with 388582 additions and 0 deletions
@@ -0,0 +1,45 @@
---
- name: Assure that default organization exists
tower_organization:
name: Default
- name: HACK - delete orphaned projects from preload data where organization deletd
tower_project:
name: "{{ item['id'] }}"
scm_type: git
state: absent
loop: >
{{ query('awx.awx.tower_api', 'projects',
query_params={'organization__isnull': true, 'name': 'Demo Project'})
}}
loop_control:
label: "Deleting Demo Project with null organization id={{ item['id'] }}"
- name: Assure that demo project exists
tower_project:
name: "Demo Project"
scm_type: 'git'
scm_url: 'https://github.com/ansible/ansible-tower-samples'
scm_update_on_launch: true
organization: Default
- name: Assure that demo inventory exists
tower_inventory:
name: "Demo Inventory"
organization: Default
- name: Create a Host
tower_host:
name: "localhost"
inventory: "Demo Inventory"
state: present
variables:
ansible_connection: local
register: result
- name: Assure that demo job template exists
tower_job_template:
name: "Demo Job Template"
project: "Demo Project"
inventory: "Demo Inventory"
playbook: "hello_world.yml"
@@ -0,0 +1,94 @@
---
- name: Generate a random string for test
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
when: test_id is not defined
- name: Generate names
set_fact:
inv_name: "AWX-Collection-tests-tower_tower_ad_hoc_command-inventory-{{ test_id }}"
ssh_cred_name: "AWX-Collection-tests-tower_tower_ad_hoc_command-ssh-cred-{{ test_id }}"
org_name: "AWX-Collection-tests-tower_tower_ad_hoc_command-org-{{ test_id }}"
- name: Create a New Organization
tower_organization:
name: "{{ org_name }}"
- name: Create an Inventory
tower_inventory:
name: "{{ inv_name }}"
organization: "{{ org_name }}"
state: present
- name: Add localhost to the Inventory
tower_host:
name: localhost
inventory: "{{ inv_name }}"
variables:
ansible_connection: local
- name: Create a Credential
tower_credential:
name: "{{ ssh_cred_name }}"
organization: "{{ org_name }}"
credential_type: 'Machine'
state: present
- name: Launch an Ad Hoc Command waiting for it to finish
tower_ad_hoc_command:
inventory: "{{ inv_name }}"
credential: "{{ ssh_cred_name }}"
module_name: "command"
module_args: "echo I <3 Ansible"
wait: true
register: result
- assert:
that:
- "result is changed"
- "result.status == 'successful'"
- name: Launch an Ad Hoc Command without module argument
tower_ad_hoc_command:
inventory: "Demo Inventory"
credential: "{{ ssh_cred_name }}"
module_name: "ping"
wait: true
register: result
- assert:
that:
- "result is changed"
- "result.status == 'successful'"
- name: Check module fails with correct msg
tower_ad_hoc_command:
inventory: "{{ inv_name }}"
credential: "{{ ssh_cred_name }}"
module_name: "Does not exist"
register: result
ignore_errors: true
- assert:
that:
- "result is failed"
- "result is not changed"
- "'Does not exist' in result.response['json']['module_name'][0]"
- name: Delete the Credential
tower_credential:
name: "{{ ssh_cred_name }}"
organization: "{{ org_name }}"
credential_type: 'Machine'
state: absent
- name: Delete the Inventory
tower_inventory:
name: "{{ inv_name }}"
organization: "{{ org_name }}"
state: absent
- name: Remove the Organization
tower_organization:
name: "{{ org_name }}"
state: absent
@@ -0,0 +1,108 @@
---
- name: Generate a random string for test
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
when: test_id is not defined
- name: Generate names
set_fact:
inv_name: "AWX-Collection-tests-tower_tower_ad_hoc_command_cancel-inventory-{{ test_id }}"
ssh_cred_name: "AWX-Collection-tests-tower_tower_ad_hoc_command_cancel-ssh-cred-{{ test_id }}"
org_name: "AWX-Collection-tests-tower_tower_ad_hoc_command_cancel-org-{{ test_id }}"
- name: Create a New Organization
tower_organization:
name: "{{ org_name }}"
- name: Create an Inventory
tower_inventory:
name: "{{ inv_name }}"
organization: "{{ org_name }}"
state: present
- name: Add localhost to the Inventory
tower_host:
name: localhost
inventory: "{{ inv_name }}"
variables:
ansible_connection: local
- name: Create a Credential
tower_credential:
name: "{{ ssh_cred_name }}"
organization: "{{ org_name }}"
credential_type: 'Machine'
state: present
- name: Launch an Ad Hoc Command
tower_ad_hoc_command:
inventory: "{{ inv_name }}"
credential: "{{ ssh_cred_name }}"
module_name: "command"
module_args: "sleep 100"
register: command
- assert:
that:
- "command is changed"
- name: Timeout waiting for the command to cancel
tower_ad_hoc_command_cancel:
command_id: "{{ command.id }}"
timeout: -1
register: results
ignore_errors: true
- assert:
that:
- results is failed
- "results['msg'] == 'Monitoring of ad hoc command aborted due to timeout'"
- name: Cancel the command with hard error if it's not running
tower_ad_hoc_command_cancel:
command_id: "{{ command.id }}"
fail_if_not_running: true
register: results
- assert:
that:
- results is changed
- name: Cancel an already canceled command (assert failure)
tower_ad_hoc_command_cancel:
command_id: "{{ command.id }}"
fail_if_not_running: true
register: results
ignore_errors: true
- assert:
that:
- results is failed
- name: Check module fails with correct msg
tower_ad_hoc_command_cancel:
command_id: 9999999999
register: result
ignore_errors: true
- assert:
that:
- "result.msg == 'Unable to find command with id 9999999999'"
- name: Delete the Credential
tower_credential:
name: "{{ ssh_cred_name }}"
organization: "{{ org_name }}"
credential_type: 'Machine'
state: absent
- name: Delete the Inventory
tower_inventory:
name: "{{ inv_name }}"
organization: "{{ org_name }}"
state: absent
- name: Remove the Organization
tower_organization:
name: "{{ org_name }}"
state: absent
@@ -0,0 +1,131 @@
---
- name: Generate a random string for test
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
when: test_id is not defined
- name: Generate names
set_fact:
inv_name: "AWX-Collection-tests-tower_ad_hoc_command_wait-inventory-{{ test_id }}"
ssh_cred_name: "AWX-Collection-tests-tower_ad_hoc_command_wait-ssh-cred-{{ test_id }}"
org_name: "AWX-Collection-tests-tower_ad_hoc_command_wait-org-{{ test_id }}"
- name: Create a New Organization
tower_organization:
name: "{{ org_name }}"
- name: Create an Inventory
tower_inventory:
name: "{{ inv_name }}"
organization: "{{ org_name }}"
state: present
- name: Add localhost to the Inventory
tower_host:
name: localhost
inventory: "{{ inv_name }}"
variables:
ansible_connection: local
- name: Create a Credential
tower_credential:
name: "{{ ssh_cred_name }}"
organization: "{{ org_name }}"
credential_type: 'Machine'
state: present
- name: Check module fails with correct msg
tower_ad_hoc_command_wait:
command_id: "99999999"
register: result
ignore_errors: true
- assert:
that:
- result is failed
- "result.msg == 'Unable to wait on ad hoc command 99999999; that ID does not exist in Tower.'"
- name: Launch command module with sleep 10
tower_ad_hoc_command:
inventory: "{{ inv_name }}"
credential: "{{ ssh_cred_name }}"
module_name: "command"
module_args: "sleep 5"
register: command
- assert:
that:
- command is changed
- name: Wait for the Job to finish
tower_ad_hoc_command_wait:
command_id: "{{ command.id }}"
register: wait_results
# Make sure it worked and that we have some data in our results
- assert:
that:
- wait_results is successful
- "'elapsed' in wait_results"
- "'id' in wait_results"
- name: Launch a long running command
tower_ad_hoc_command:
inventory: "{{ inv_name }}"
credential: "{{ ssh_cred_name }}"
module_name: "command"
module_args: "sleep 10000"
register: command
- assert:
that:
- command is changed
- name: Timeout waiting for the command to complete
tower_ad_hoc_command_wait:
command_id: "{{ command.id }}"
timeout: 1
ignore_errors: true
register: wait_results
# Make sure that we failed and that we have some data in our results
- assert:
that:
- "'Monitoring aborted due to timeout' or 'Timeout waiting for command to finish.' in wait_results.msg"
- "'id' in wait_results"
- name: Async cancel the long-running command
tower_ad_hoc_command_cancel:
command_id: "{{ command.id }}"
async: 3600
poll: 0
- name: Wait for the command to exit on cancel
tower_ad_hoc_command_wait:
command_id: "{{ command.id }}"
register: wait_results
ignore_errors: true
- assert:
that:
- wait_results is failed
- 'wait_results.status == "canceled"'
- "wait_results.msg == 'The ad hoc command - {{ command.id }}, failed'"
- name: Delete the Credential
tower_credential:
name: "{{ ssh_cred_name }}"
organization: "{{ org_name }}"
credential_type: 'Machine'
state: absent
- name: Delete the Inventory
tower_inventory:
name: "{{ inv_name }}"
organization: "{{ org_name }}"
state: absent
- name: Remove the Organization
tower_organization:
name: "{{ org_name }}"
state: absent
@@ -0,0 +1,79 @@
---
- name: Generate a test id
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Generate names
set_fact:
app1_name: "AWX-Collection-tests-tower_application-app1-{{ test_id }}"
app2_name: "AWX-Collection-tests-tower_application-app2-{{ test_id }}"
app3_name: "AWX-Collection-tests-tower_application-app3-{{ test_id }}"
- block:
- name: Create an application
tower_application:
name: "{{ app1_name }}"
authorization_grant_type: "password"
client_type: "public"
organization: "Default"
state: present
register: result
- assert:
that:
- "result is changed"
- name: Delete our application
tower_application:
name: "{{ app1_name }}"
organization: "Default"
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Create a second application
tower_application:
name: "{{ app2_name }}"
authorization_grant_type: "authorization-code"
client_type: "confidential"
organization: "Default"
description: "Another application"
redirect_uris:
- http://tower.com/api/v2/
- http://tower.com/api/v2/teams
state: present
register: result
- assert:
that:
- "result is changed"
- name: Create an all trusting application
tower_application:
name: "{{ app3_name }}"
organization: "Default"
description: "All Trusting Application"
skip_authorization: true
authorization_grant_type: "password"
client_type: "confidential"
state: present
register: result
- assert:
that:
- "result is changed"
always:
- name: Delete our application
tower_application:
name: "{{ item }}"
organization: "Default"
state: absent
register: result
loop:
- "{{ app1_name }}"
- "{{ app2_name }}"
- "{{ app3_name }}"
@@ -0,0 +1,730 @@
---
- name: Generate a random string for test
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
when: test_id is not defined
- name: Generate names
set_fact:
ssh_cred_name1: "AWX-Collection-tests-tower_credential-ssh-cred1-{{ test_id }}"
ssh_cred_name2: "AWX-Collection-tests-tower_credential-ssh-cred2-{{ test_id }}"
ssh_cred_name3: "AWX-Collection-tests-tower_credential-ssh-cred-lookup-source-{{ test_id }}"
ssh_cred_name4: "AWX-Collection-tests-tower_credential-ssh-cred-file-source-{{ test_id }}"
vault_cred_name1: "AWX-Collection-tests-tower_credential-vault-cred1-{{ test_id }}"
vault_cred_name2: "AWX-Collection-tests-tower_credential-vault-ssh-cred1-{{ test_id }}"
net_cred_name1: "AWX-Collection-tests-tower_credential-net-cred1-{{ test_id }}"
scm_cred_name1: "AWX-Collection-tests-tower_credential-scm-cred1-{{ test_id }}"
aws_cred_name1: "AWX-Collection-tests-tower_credential-aws-cred1-{{ test_id }}"
vmware_cred_name1: "AWX-Collection-tests-tower_credential-vmware-cred1-{{ test_id }}"
sat6_cred_name1: "AWX-Collection-tests-tower_credential-sat6-cred1-{{ test_id }}"
gce_cred_name1: "AWX-Collection-tests-tower_credential-gce-cred1-{{ test_id }}"
azurerm_cred_name1: "AWX-Collection-tests-tower_credential-azurerm-cred1-{{ test_id }}"
openstack_cred_name1: "AWX-Collection-tests-tower_credential-openstack-cred1-{{ test_id }}"
rhv_cred_name1: "AWX-Collection-tests-tower_credential-rhv-cred1-{{ test_id }}"
insights_cred_name1: "AWX-Collection-tests-tower_credential-insights-cred1-{{ test_id }}"
tower_cred_name1: "AWX-Collection-tests-tower_credential-tower-cred1-{{ test_id }}"
- name: create a tempdir for an SSH key
local_action: shell mktemp -d
register: tempdir
- name: Generate a local SSH key
local_action: "shell ssh-keygen -b 2048 -t rsa -f {{ tempdir.stdout }}/id_rsa -q -N 'passphrase'"
- name: Read the generated key
set_fact:
ssh_key_data: "{{ lookup('file', tempdir.stdout + '/id_rsa') }}"
- name: Test deprecation warnings
tower_credential:
name: "{{ ssh_cred_name1 }}"
organization: Default
kind: ssh
authorize: false
authorize_password: 'test'
client: 'test'
security_token: 'test'
secret: 'test'
tenant: 'test'
subscription: 'test'
domain: 'test'
become_method: 'test'
become_username: 'test'
become_password: 'test'
vault_password: 'test'
project: 'test'
host: 'test'
username: 'test'
password: 'test'
ssh_key_data: 'test'
vault_id: 'test'
ssh_key_unlock: 'test'
state: absent
ignore_errors: true
register: result
- assert:
that:
- "'deprecations' in result"
# The 20 comes from the length of OLD_INPUT_NAMES + 1 for kind
- result['deprecations'] | length() == 20
- name: Create an Org-specific credential (old school)
tower_credential:
name: "{{ ssh_cred_name1 }}"
organization: Default
state: present
kind: ssh
register: result
- assert:
that:
- "result is changed"
- name: Re-create the Org-specific credential (new school) with an ID
tower_credential:
name: "{{ result.id }}"
organization: Default
credential_type: 'Machine'
state: present
register: result
- assert:
that:
- "result is not changed"
- name: Delete a Org-specific credential
tower_credential:
name: "{{ ssh_cred_name1 }}"
organization: Default
state: absent
kind: ssh
register: result
- assert:
that:
- "result is changed"
- name: Create the User-specific credential
tower_credential:
name: "{{ ssh_cred_name1 }}"
user: admin
credential_type: 'Machine'
state: present
register: result
- assert:
that:
- "result is changed"
- name: Delete a User-specific credential
tower_credential:
name: "{{ ssh_cred_name1 }}"
user: admin
state: absent
kind: ssh
register: result
- assert:
that:
- "result is changed"
- name: Create a valid SSH credential (old school)
tower_credential:
name: "{{ ssh_cred_name2 }}"
organization: Default
state: present
kind: ssh
description: An example SSH credential
username: joe
password: secret
become_method: sudo
become_username: superuser
become_password: supersecret
ssh_key_data: "{{ ssh_key_data }}"
ssh_key_unlock: "passphrase"
register: result
- assert:
that:
- "result is changed"
- name: Create a valid SSH credential (new school)
tower_credential:
name: "{{ ssh_cred_name2 }}"
organization: Default
state: present
credential_type: Machine
description: An example SSH credential
inputs:
username: joe
password: secret
become_method: sudo
become_username: superuser
become_password: supersecret
ssh_key_data: "{{ ssh_key_data }}"
ssh_key_unlock: "passphrase"
register: result
# This will be changed because we are setting ssh_key_data and ssh_key_unlock.
# These will come out as $encrypted$ which will always compare false to the values.
- assert:
that:
- result is changed
- name: Create a valid SSH credential (new school)
tower_credential:
name: "{{ ssh_cred_name2 }}"
organization: Default
state: present
credential_type: Machine
description: An example SSH credential
inputs:
username: joe
become_method: sudo
become_username: superuser
register: result
# This shows as "changed" because these listed inputs replace the existing inputs from the previous task
- assert:
that:
- result is changed
- name: Check for inputs idempotency (when "inputs" is blank)
tower_credential:
name: "{{ ssh_cred_name2 }}"
organization: Default
state: present
credential_type: Machine
description: An example SSH credential
register: result
- assert:
that:
- result is not changed
- name: Create a valid SSH credential from lookup source (old school)
tower_credential:
name: "{{ ssh_cred_name3 }}"
organization: Default
state: present
kind: ssh
description: An example SSH credential from lookup source
username: joe
password: secret
become_method: sudo
become_username: superuser
become_password: supersecret
ssh_key_data: "{{ lookup('file', tempdir.stdout + '/id_rsa') }}"
ssh_key_unlock: "passphrase"
register: result
- assert:
that:
- "result is changed"
- name: Create a valid SSH credential from lookup source (new school)
tower_credential:
name: "{{ ssh_cred_name3 }}"
organization: Default
state: present
credential_type: Machine
description: An example SSH credential from lookup source
inputs:
username: joe
password: secret
become_method: sudo
become_username: superuser
become_password: supersecret
ssh_key_data: "{{ lookup('file', tempdir.stdout + '/id_rsa') }}"
ssh_key_unlock: "passphrase"
register: result
# This will be changed because we are passing in ssh_key_data and password
- assert:
that:
- result is changed
- name: Fail to create an SSH credential from a file source (old school format)
tower_credential:
name: "{{ ssh_cred_name4 }}"
organization: Default
state: present
kind: ssh
description: An example SSH credential from file source
username: joe
password: secret
become_method: sudo
become_username: superuser
become_password: supersecret
ssh_key_data: "{{ tempdir.stdout }}/id_rsa"
ssh_key_unlock: "passphrase"
register: result
ignore_errors: true
- assert:
that:
- result is failed
- "'Unable to create credential {{ ssh_cred_name4 }}' in result.msg"
- "'Invalid certificate or key' in result.msg"
- name: Create an invalid SSH credential (passphrase required)
tower_credential:
name: SSH Credential
organization: Default
state: present
kind: ssh
username: joe
ssh_key_data: "{{ ssh_key_data }}"
ignore_errors: true
register: result
- assert:
that:
- "result is failed"
- "'must be set when SSH key is encrypted' in result.msg"
- name: Create an invalid SSH credential (Organization not found)
tower_credential:
name: SSH Credential
organization: Missing_Organization
state: present
kind: ssh
username: joe
ignore_errors: true
register: result
- assert:
that:
- "result is failed"
- "result is not changed"
- "'Missing_Organization' in result.msg"
- "result.total_results == 0"
- name: Delete an SSH credential
tower_credential:
name: "{{ ssh_cred_name2 }}"
organization: Default
state: absent
kind: ssh
register: result
- assert:
that:
- "result is changed"
- name: Delete an SSH credential
tower_credential:
name: "{{ ssh_cred_name3 }}"
organization: Default
state: absent
kind: ssh
register: result
- assert:
that:
- "result is changed"
- name: Delete an SSH credential
tower_credential:
name: "{{ ssh_cred_name4 }}"
organization: Default
state: absent
kind: ssh
register: result
# This one was never really created so it shouldn't be deleted
- assert:
that:
- "result is not changed"
- name: Create a valid Vault credential
tower_credential:
name: "{{ vault_cred_name1 }}"
organization: Default
state: present
kind: vault
description: An example Vault credential
vault_password: secret-vault
register: result
- assert:
that:
- "result is changed"
# We should decide when to delete this test
- name: Create a valid Vault credential w/ kind=ssh (deprecated, will now fail)
tower_credential:
name: "{{ vault_cred_name2 }}"
organization: Default
state: present
kind: ssh
description: An example Vault credential
vault_password: secret-vault
register: result
ignore_errors: true
- assert:
that:
- result is failed
- "'Unable to create credential {{ vault_cred_name2 }}' in result.msg"
- "'Additional properties are not allowed' in result.msg"
- "'\\'vault_password\\' was unexpected' in result.msg"
- name: Delete a Vault credential
tower_credential:
name: "{{ vault_cred_name1 }}"
organization: Default
state: absent
kind: vault
register: result
- assert:
that:
- "result is changed"
- name: Delete a Vault credential
tower_credential:
name: "{{ vault_cred_name2 }}"
organization: Default
state: absent
kind: vault
register: result
# The creation of vault_cred_name2 never worked so we shouldn't actually need to delete it
- assert:
that:
- "result is not changed"
- name: Create a valid Network credential
tower_credential:
name: "{{ net_cred_name1 }}"
organization: Default
state: present
kind: net
username: joe
password: secret
authorize: true
authorize_password: authorize-me
register: result
- assert:
that:
- "result is changed"
- name: Delete a Network credential
tower_credential:
name: "{{ net_cred_name1 }}"
organization: Default
state: absent
kind: net
register: result
- assert:
that:
- "result is changed"
- name: Create a valid SCM credential
tower_credential:
name: "{{ scm_cred_name1 }}"
organization: Default
state: present
kind: scm
username: joe
password: secret
ssh_key_data: "{{ ssh_key_data }}"
ssh_key_unlock: "passphrase"
register: result
- assert:
that:
- "result is changed"
- name: Delete an SCM credential
tower_credential:
name: "{{ scm_cred_name1 }}"
organization: Default
state: absent
kind: scm
register: result
- assert:
that:
- "result is changed"
- name: Create a valid AWS credential
tower_credential:
name: "{{ aws_cred_name1 }}"
organization: Default
state: present
kind: aws
username: joe
password: secret
security_token: aws-token
register: result
- assert:
that:
- "result is changed"
- name: Delete an AWS credential
tower_credential:
name: "{{ aws_cred_name1 }}"
organization: Default
state: absent
kind: aws
register: result
- assert:
that:
- "result is changed"
- name: Create a valid VMWare credential
tower_credential:
name: "{{ vmware_cred_name1 }}"
organization: Default
state: present
kind: vmware
host: https://example.org
username: joe
password: secret
register: result
- assert:
that:
- "result is changed"
- name: Delete an VMWare credential
tower_credential:
name: "{{ vmware_cred_name1 }}"
organization: Default
state: absent
kind: vmware
register: result
- assert:
that:
- "result is changed"
- name: Create a valid Satellite6 credential
tower_credential:
name: "{{ sat6_cred_name1 }}"
organization: Default
state: present
kind: satellite6
host: https://example.org
username: joe
password: secret
register: result
- assert:
that:
- "result is changed"
- name: Delete a Satellite6 credential
tower_credential:
name: "{{ sat6_cred_name1 }}"
organization: Default
state: absent
kind: satellite6
register: result
- assert:
that:
- "result is changed"
- name: Create a valid GCE credential
tower_credential:
name: "{{ gce_cred_name1 }}"
organization: Default
state: present
kind: gce
username: joe
project: ABC123
ssh_key_data: "{{ ssh_key_data }}"
register: result
- assert:
that:
- "result is changed"
- name: Delete a GCE credential
tower_credential:
name: "{{ gce_cred_name1 }}"
organization: Default
state: absent
kind: gce
register: result
- assert:
that:
- "result is changed"
- name: Create a valid AzureRM credential
tower_credential:
name: "{{ azurerm_cred_name1 }}"
organization: Default
state: present
kind: azure_rm
username: joe
password: secret
subscription: some-subscription
register: result
- assert:
that:
- "result is changed"
- name: Create a valid AzureRM credential with a tenant
tower_credential:
name: "{{ azurerm_cred_name1 }}"
organization: Default
state: present
kind: azure_rm
client: some-client
secret: some-secret
tenant: some-tenant
subscription: some-subscription
register: result
- assert:
that:
- "result is changed"
- name: Delete an AzureRM credential
tower_credential:
name: "{{ azurerm_cred_name1 }}"
organization: Default
state: absent
kind: azure_rm
register: result
- assert:
that:
- "result is changed"
- name: Create a valid OpenStack credential
tower_credential:
name: "{{ openstack_cred_name1 }}"
organization: Default
state: present
kind: openstack
host: https://keystone.example.org
username: joe
password: secret
project: tenant123
domain: some-domain
register: result
- assert:
that:
- "result is changed"
- name: Delete a OpenStack credential
tower_credential:
name: "{{ openstack_cred_name1 }}"
organization: Default
state: absent
kind: openstack
register: result
- assert:
that:
- "result is changed"
- name: Create a valid RHV credential
tower_credential:
name: "{{ rhv_cred_name1 }}"
organization: Default
state: present
kind: rhv
host: https://example.org
username: joe
password: secret
register: result
- assert:
that:
- "result is changed"
- name: Delete an RHV credential
tower_credential:
name: "{{ rhv_cred_name1 }}"
organization: Default
state: absent
kind: rhv
register: result
- assert:
that:
- "result is changed"
- name: Create a valid Insights credential
tower_credential:
name: "{{ insights_cred_name1 }}"
organization: Default
state: present
kind: insights
username: joe
password: secret
register: result
- assert:
that:
- "result is changed"
- name: Delete an Insights credential
tower_credential:
name: "{{ insights_cred_name1 }}"
organization: Default
state: absent
kind: insights
register: result
- assert:
that:
- "result is changed"
- name: Create a valid Tower-to-Tower credential
tower_credential:
name: "{{ tower_cred_name1 }}"
organization: Default
state: present
kind: tower
host: https://tower.example.org
username: joe
password: secret
register: result
- assert:
that:
- "result is changed"
- name: Delete a Tower-to-Tower credential
tower_credential:
name: "{{ tower_cred_name1 }}"
organization: Default
state: absent
kind: tower
register: result
- assert:
that:
- "result is changed"
- name: Check module fails with correct msg
tower_credential:
name: test-credential
description: Credential Description
kind: ssh
organization: test-non-existing-org
state: present
register: result
ignore_errors: true
- assert:
that:
- "result is failed"
- "result is not changed"
- "'test-non-existing-org' in result.msg"
- "result.total_results == 0"
@@ -0,0 +1,113 @@
---
- name: Generate a random string for test
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
when: test_id is not defined
- name: Generate names
set_fact:
src_cred_name: "AWX-Collection-tests-tower_credential_input_source-src_cred-{{ test_id }}"
target_cred_name: "AWX-Collection-tests-tower_credential_input_source-target_cred-{{ test_id }}"
- block:
- name: Add Tower credential Lookup
tower_credential:
description: Credential for Testing Source
name: "{{ src_cred_name }}"
credential_type: CyberArk AIM Central Credential Provider Lookup
inputs:
url: "https://cyberark.example.com"
app_id: "My-App-ID"
organization: Default
register: src_cred_result
- assert:
that:
- "src_cred_result is changed"
- name: Add Tower credential Target
tower_credential:
description: Credential for Testing Target
name: "{{ target_cred_name }}"
credential_type: Machine
inputs:
username: user
organization: Default
register: target_cred_result
- assert:
that:
- "target_cred_result is changed"
- name: Add credential Input Source
tower_credential_input_source:
input_field_name: password
target_credential: "{{ target_cred_result.id }}"
source_credential: "{{ src_cred_result.id }}"
metadata:
object_query: "Safe=MY_SAFE;Object=AWX-user"
object_query_format: "Exact"
state: present
register: result
- assert:
that:
- "result is changed"
- name: Add Second Tower credential Lookup
tower_credential:
description: Credential for Testing Source Change
name: "{{ src_cred_name }}-2"
credential_type: CyberArk AIM Central Credential Provider Lookup
inputs:
url: "https://cyberark-prod.example.com"
app_id: "My-App-ID"
organization: Default
register: result
- name: Change credential Input Source
tower_credential_input_source:
input_field_name: password
target_credential: "{{ target_cred_name }}"
source_credential: "{{ src_cred_name }}-2"
state: present
- assert:
that:
- "result is changed"
always:
- name: Remove a Tower credential source
tower_credential_input_source:
input_field_name: password
target_credential: "{{ target_cred_name }}"
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Remove Tower credential Lookup
tower_credential:
name: "{{ src_cred_name }}"
organization: Default
credential_type: CyberArk AIM Central Credential Provider Lookup
state: absent
register: result
- name: Remove Alt Tower credential Lookup
tower_credential:
name: "{{ src_cred_name }}-2"
organization: Default
credential_type: CyberArk AIM Central Credential Provider Lookup
state: absent
register: result
- name: Remove Tower credential
tower_credential:
name: "{{ target_cred_name }}"
organization: Default
credential_type: Machine
state: absent
register: result
@@ -0,0 +1,27 @@
---
- name: Generate names
set_fact:
cred_type_name: "AWX-Collection-tests-tower_credential_type-cred-type-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Add Tower credential type
tower_credential_type:
description: Credential type for Test
name: "{{ cred_type_name }}"
kind: cloud
inputs: {"fields": [{"type": "string", "id": "username", "label": "Username"}, {"secret": true, "type": "string", "id": "password", "label": "Password"}], "required": ["username", "password"]}
injectors: {"extra_vars": {"test": "foo"}}
register: result
- assert:
that:
- "result is changed"
- name: Remove a Tower credential type
tower_credential_type:
name: "{{ result.id }}"
state: absent
register: result
- assert:
that:
- "result is changed"
@@ -0,0 +1 @@
skip/python2
@@ -0,0 +1,77 @@
---
- name: Generate a random string for test
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
when: test_id is not defined
- name: Generate names
set_fact:
org_name1: "AWX-Collection-tests-tower_export-organization-{{ test_id }}"
org_name2: "AWX-Collection-tests-tower_export-organization2-{{ test_id }}"
inventory_name1: "AWX-Collection-tests-tower_export-inv1-{{ test_id }}"
- block:
- name: Create some organizations
tower_organization:
name: "{{ item }}"
loop:
- "{{ org_name1 }}"
- "{{ org_name2 }}"
- name: Create an inventory
tower_inventory:
name: "{{ inventory_name1 }}"
organization: "{{ org_name1 }}"
- name: Export all tower assets
tower_export:
all: true
register: all_assets
- assert:
that:
- all_assets is not changed
- all_assets is successful
- all_assets['assets']['organizations'] | length() >= 2
- name: Export all inventories
tower_export:
inventory: 'all'
register: inventory_export
- assert:
that:
- inventory_export is successful
- inventory_export is not changed
- inventory_export['assets']['inventory'] | length() >= 1
- "'organizations' not in inventory_export['assets']"
# This mimics the example in the module
- name: Export an all and a specific
tower_export:
inventory: 'all'
organizations: "{{ org_name1 }}"
register: mixed_export
- assert:
that:
- mixed_export is successful
- mixed_export is not changed
- mixed_export['assets']['inventory'] | length() >= 1
- mixed_export['assets']['organizations'] | length() == 1
- "'workflow_job_templates' not in mixed_export['assets']"
always:
- name: Remove our inventory
tower_inventory:
name: "{{ inventory_name1 }}"
organization: "{{ org_name1 }}"
state: absent
- name: Remove test organizations
tower_organization:
name: "{{ item }}"
state: absent
loop:
- "{{ org_name1 }}"
- "{{ org_name2 }}"
@@ -0,0 +1,101 @@
---
- name: Generate names
set_fact:
group_name1: "AWX-Collection-tests-tower_group-group-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
group_name2: "AWX-Collection-tests-tower_group-group-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
group_name3: "AWX-Collection-tests-tower_group-group-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
inv_name: "AWX-Collection-test-tower_group-inv-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
host_name1: "AWX-Collection-test-tower_group-host-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
host_name2: "AWX-Collection-test-tower_group-host-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
host_name3: "AWX-Collection-test-tower_group-host-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Create an Inventory
tower_inventory:
name: "{{ inv_name }}"
organization: Default
state: present
register: result
- name: Create a Group
tower_group:
name: "{{ group_name1 }}"
inventory: "{{ result.id }}"
state: present
variables:
foo: bar
register: result
- assert:
that:
- "result is changed"
- name: Delete a Group
tower_group:
name: "{{ result.id }}"
inventory: "{{ inv_name }}"
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Check module fails with correct msg
tower_group:
name: test-group
description: Group Description
inventory: test-non-existing-inventory
state: present
register: result
ignore_errors: true
- assert:
that:
- "result is failed"
- "result is not changed"
- "'test-non-existing-inventory' in result.msg"
- "result.total_results == 0"
- name: add hosts
tower_host:
name: "{{ item }}"
inventory: "{{ inv_name }}"
loop:
- "{{ host_name1 }}"
- "{{ host_name2 }}"
- "{{ host_name3 }}"
- name: add mid level group
tower_group:
name: "{{ group_name2 }}"
inventory: "{{ inv_name }}"
hosts:
- "{{ host_name3 }}"
- name: add top group
tower_group:
name: "{{ group_name3 }}"
inventory: "{{ inv_name }}"
hosts:
- "{{ host_name1 }}"
- "{{ host_name2 }}"
children:
- "{{ group_name2 }}"
- name: Delete the parent group
tower_group:
name: "{{ group_name3 }}"
inventory: "{{ inv_name }}"
state: absent
- name: Delete the child group
tower_group:
name: "{{ group_name2 }}"
inventory: "{{ inv_name }}"
state: absent
- name: Delete an Inventory
tower_inventory:
name: "{{ inv_name }}"
organization: Default
state: absent
@@ -0,0 +1,51 @@
---
- name: Generate names
set_fact:
host_name: "AWX-Collection-tests-tower_host-host-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
inv_name: "AWX-Collection-tests-tower_host-inv-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Create an Inventory
tower_inventory:
name: "{{ inv_name }}"
organization: Default
state: present
register: result
- name: Create a Host
tower_host:
name: "{{ host_name }}"
inventory: "{{ result.id }}"
state: present
variables:
foo: bar
register: result
- assert:
that:
- "result is changed"
- name: Delete a Host
tower_host:
name: "{{ result.id }}"
inventory: "{{ inv_name }}"
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Check module fails with correct msg
tower_host:
name: test-host
description: Host Description
inventory: test-non-existing-inventory
state: present
register: result
ignore_errors: true
- assert:
that:
- "result is failed"
- "'test-non-existing-inventory' in result.msg"
- "result.total_results == 0"
@@ -0,0 +1 @@
skip/python2
@@ -0,0 +1,108 @@
---
- name: Generate a random string for test
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
when: test_id is not defined
- name: Generate names
set_fact:
org_name1: "AWX-Collection-tests-tower_import-organization-{{ test_id }}"
org_name2: "AWX-Collection-tests-tower_import-organization2-{{ test_id }}"
- block:
- name: "Import something"
tower_import:
assets:
organizations:
- name: "{{ org_name1 }}"
description: ""
max_hosts: 0
custom_virtualenv: null
related:
notification_templates: []
notification_templates_started: []
notification_templates_success: []
notification_templates_error: []
notification_templates_approvals: []
natural_key:
name: "{{ org_name1 }}"
type: "organization"
register: import_output
- assert:
that:
- import_output is changed
- name: "Import the same thing again"
tower_import:
assets:
organizations:
- name: "{{ org_name1 }}"
description: ""
max_hosts: 0
custom_virtualenv: null
related:
notification_templates: []
notification_templates_started: []
notification_templates_success: []
notification_templates_error: []
notification_templates_approvals: []
natural_key:
name: "{{ org_name1 }}"
type: "organization"
register: import_output
ignore_errors: true
- assert:
that:
- import_output is not failed
# - import_output is not changed # FIXME: module not idempotent
- name: "Write out a json file"
copy:
content: |
{
"organizations": [
{
"name": "{{ org_name2 }}",
"description": "",
"max_hosts": 0,
"custom_virtualenv": null,
"related": {
"notification_templates": [],
"notification_templates_started": [],
"notification_templates_success": [],
"notification_templates_error": [],
"notification_templates_approvals": []
},
"natural_key": {
"name": "{{ org_name2 }}",
"type": "organization"
}
}
]
}
dest: ./org.json
- name: "Load assets from a file"
tower_import:
assets: "{{ lookup('file', 'org.json') | from_json() }}"
register: import_output
- assert:
that:
- import_output is changed
always:
- name: Remove organizations
tower_organization:
name: "{{ item }}"
state: absent
loop:
- "{{ org_name1 }}"
- "{{ org_name2 }}"
- name: Delete org.json
file:
path: ./org.json
state: absent
@@ -0,0 +1,75 @@
---
- name: Generate test id
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Generate names
set_fact:
group_name1: "AWX-Collection-tests-tower_instance_group-group1-{{ test_id }}"
group_name2: "AWX-Collection-tests-tower_instance_group-group2-{{ test_id }}"
cred_name1: "AWX-Collection-tests-tower_instance_group-cred1-{{ test_id }}"
- block:
- name: Create an OpenShift Credential
tower_credential:
name: "{{ cred_name1 }}"
organization: "Default"
credential_type: "OpenShift or Kubernetes API Bearer Token"
inputs:
host: "https://openshift.org"
bearer_token: "asdf1234"
verify_ssl: false
register: cred_result
- assert:
that:
- "cred_result is changed"
- name: Create an Instance Group
tower_instance_group:
name: "{{ group_name1 }}"
policy_instance_percentage: 34
policy_instance_minimum: 12
state: present
register: result
- assert:
that:
- "result is changed"
- name: Update an Instance Group
tower_instance_group:
name: "{{ result.id }}"
policy_instance_percentage: 34
policy_instance_minimum: 24
state: present
register: result
- assert:
that:
- "result is changed"
- name: Create a container group
tower_instance_group:
name: "{{ group_name2 }}"
credential: "{{ cred_result.id }}"
register: result
- assert:
that:
- "result is changed"
always:
- name: Delete the instance groups
tower_instance_group:
name: "{{ item }}"
state: absent
loop:
- "{{ group_name1 }}"
- "{{ group_name2 }}"
- name: Delete the credential
tower_credential:
name: "{{ cred_name1 }}"
organization: "Default"
credential_type: "OpenShift or Kubernetes API Bearer Token"
@@ -0,0 +1,142 @@
---
- name: Generate a test ID
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Generate names
set_fact:
inv_name1: "AWX-Collection-tests-tower_inventory-inv1-{{ test_id }}"
inv_name2: "AWX-Collection-tests-tower_inventory-inv2-{{ test_id }}"
cred_name1: "AWX-Collection-tests-tower_inventory-cred1-{{ test_id }}"
- block:
- name: Create an Insights Credential
tower_credential:
name: "{{ cred_name1 }}"
organization: Default
kind: insights
inputs:
username: joe
password: secret
state: present
register: result
- assert:
that:
- "result is changed"
- name: Create an Inventory
tower_inventory:
name: "{{ inv_name1 }}"
organization: Default
insights_credential: "{{ result.id }}"
state: present
register: result
- assert:
that:
- "result is changed"
- name: Test Inventory module idempotency
tower_inventory:
name: "{{ result.id }}"
organization: Default
insights_credential: "{{ cred_name1 }}"
state: present
register: result
- assert:
that:
- "result is not changed"
- name: Fail Change Regular to Smart
tower_inventory:
name: "{{ inv_name1 }}"
organization: Default
kind: smart
register: result
ignore_errors: true
- assert:
that:
- "result is failed"
- name: Create a smart inventory
tower_inventory:
name: "{{ inv_name2 }}"
organization: Default
kind: smart
host_filter: name=foo
register: result
- assert:
that:
- "result is changed"
- name: Delete a smart inventory
tower_inventory:
name: "{{ inv_name2 }}"
organization: Default
kind: smart
host_filter: name=foo
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Delete an Inventory
tower_inventory:
name: "{{ inv_name1 }}"
organization: Default
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Delete a Non-Existent Inventory
tower_inventory:
name: "{{ inv_name1 }}"
organization: Default
state: absent
register: result
- assert:
that:
- "result is not changed"
- name: Check module fails with correct msg
tower_inventory:
name: test-inventory
description: Inventory Description
organization: test-non-existing-org
state: present
register: result
ignore_errors: true
- assert:
that:
- "result is failed"
- "result is not changed"
- "'test-non-existing-org' in result.msg"
- "result.total_results == 0"
always:
- name: Delete Inventories
tower_inventory:
name: "{{ item }}"
organization: Default
state: absent
loop:
- "{{ inv_name1 }}"
- "{{ inv_name2 }}"
- name: Delete Insights Credential
tower_credential:
name: "{{ cred_name1 }}"
organization: "Default"
kind: insights
state: absent
@@ -0,0 +1,83 @@
---
- name: Generate names
set_fact:
openstack_cred: "AWX-Collection-tests-tower_inventory_source-cred-openstack-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
openstack_inv: "AWX-Collection-tests-tower_inventory_source-inv-openstack-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
openstack_inv_source: "AWX-Collection-tests-tower_inventory_source-inv-source-openstack-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Add a Tower credential
tower_credential:
description: Credentials for Openstack Test project
name: "{{ openstack_cred }}"
kind: openstack
organization: Default
project: Test
username: admin
host: https://example.org:5000
password: passw0rd
domain: test
register: credential_result
- name: Add a Tower inventory
tower_inventory:
description: Test inventory
organization: Default
name: "{{ openstack_inv }}"
- name: Create a source inventory
tower_inventory_source:
name: "{{ openstack_inv_source }}"
description: Source for Test inventory
inventory: "{{ openstack_inv }}"
credential: "{{ credential_result.id }}"
overwrite: true
update_on_launch: true
source_vars:
private: false
source: openstack
register: result
- assert:
that:
- "result is changed"
- name: Delete the inventory source with an invalid cred, source_project, sourece_script specified
tower_inventory_source:
name: "{{ result.id }}"
inventory: "{{ openstack_inv }}"
credential: "Does Not Exit"
source_project: "Does Not Exist"
source_script: "Does Not Exist"
state: absent
- assert:
that:
- "result is changed"
- name: Delete the credential
tower_credential:
description: Credentials for Openstack Test project
name: "{{ openstack_cred }}"
kind: openstack
organization: Default
project: Test
username: admin
host: https://example.org:5000
password: passw0rd
domain: test
state: absent
- assert:
that:
- "result is changed"
- name: Delete the inventory
tower_inventory:
description: Test inventory
organization: Default
name: "{{ openstack_inv }}"
state: absent
- assert:
that:
- "result is changed"
@@ -0,0 +1,131 @@
---
- name: Generate a test ID
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Generate names
set_fact:
project_name: "AWX-Collection-tests-tower_inventory_source_update-project-{{ test_id }}"
inv_name: "AWX-Collection-tests-tower_inventory_source_update-inv-{{ test_id }}"
inv_source1: "AWX-Collection-tests-tower_inventory_source_update-source1-{{ test_id }}"
inv_source2: "AWX-Collection-tests-tower_inventory_source_update-source2-{{ test_id }}"
inv_source3: "AWX-Collection-tests-tower_inventory_source_update-source3-{{ test_id }}"
org_name: "AWX-Collection-tests-tower_inventory_source_update-org-{{ test_id }}"
- block:
- name: "Create a new organization"
tower_organization:
name: "{{ org_name }}"
register: created_org
- name: Create a git project without credentials
tower_project:
name: "{{ project_name }}"
organization: "{{ org_name }}"
scm_type: git
scm_url: https://github.com/ansible/test-playbooks
wait: true
- name: Create an Inventory
tower_inventory:
name: "{{ inv_name }}"
organization: "{{ org_name }}"
state: present
- name: Create another inventory w/ same name, different org
tower_inventory:
name: "{{ inv_name }}"
organization: Default
state: present
register: created_inventory
- name: Create an Inventory Source (specifically connected to the randomly generated org)
tower_inventory_source:
name: "{{ inv_source1 }}"
source: scm
source_project: "{{ project_name }}"
source_path: inventories/inventory.ini
description: Source for Test inventory
organization: "{{ created_org.id }}"
inventory: "{{ inv_name }}"
- name: Create Another Inventory Source
tower_inventory_source:
name: "{{ inv_source2 }}"
source: scm
source_project: "{{ project_name }}"
source_path: inventories/create_10_hosts.ini
description: Source for Test inventory
organization: Default
inventory: "{{ inv_name }}"
- name: Create Yet Another Inventory Source (to make lookup plugin find multiple inv sources)
tower_inventory_source:
name: "{{ inv_source3 }}"
source: scm
source_project: "{{ project_name }}"
source_path: inventories/create_100_hosts.ini
description: Source for Test inventory
organization: Default
inventory: "{{ inv_name }}"
- name: Test Inventory Source Update
tower_inventory_source_update:
name: "{{ inv_source2 }}"
inventory: "{{ inv_name }}"
organization: Default
register: result
- assert:
that:
- "result is changed"
- name: Test Inventory Source Update for All Sources
tower_inventory_source_update:
name: "{{ item.name }}"
inventory: "{{ inv_name }}"
organization: Default
wait: true
loop: "{{ query('awx.awx.tower_api', 'inventory_sources', query_params={ 'inventory': created_inventory.id }, expect_objects=True, return_objects=True) }}"
loop_control:
label: "{{ item.name }}"
register: result
- assert:
that:
- "result is changed"
- name: Test Inventory Source Update for All Sources (using inventory_source as alias for name)
tower_inventory_source_update:
inventory_source: "{{ item.name }}"
inventory: "{{ inv_name }}"
organization: Default
wait: true
loop: "{{ query('awx.awx.tower_api', 'inventory_sources', query_params={ 'inventory': created_inventory.id }, expect_objects=True, return_objects=True) }}"
loop_control:
label: "{{ item.name }}"
register: result
- assert:
that:
- "result is changed"
always:
- name: Delete Inventory
tower_inventory:
name: "{{ inv_name }}"
organization: Default
state: absent
- name: Delete Project
tower_project:
name: "{{ project_name }}"
organization: Default
state: absent
- name: "Remove the organization"
tower_organization:
name: "{{ org_name }}"
state: absent
@@ -0,0 +1,40 @@
---
- name: Launch a Job Template
tower_job_launch:
job_template: "Demo Job Template"
register: job
- assert:
that:
- "job is changed"
- name: Cancel the job
tower_job_cancel:
job_id: "{{ job.id }}"
register: results
- assert:
that:
- results is changed
- name: Cancel an already canceled job (assert failure)
tower_job_cancel:
job_id: "{{ job.id }}"
fail_if_not_running: true
register: results
ignore_errors: true
- assert:
that:
- results is failed
- name: Check module fails with correct msg
tower_job_cancel:
job_id: 9999999999
register: result
ignore_errors: true
- assert:
that:
- "result.msg =='Unable to cancel job_id/9999999999: The requested object could not be found.'
or result.msg =='Unable to find job with id 9999999999'"
@@ -0,0 +1,209 @@
---
- name: Generate names
set_fact:
jt_name1: "AWX-Collection-tests-tower_job_launch-jt1-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
jt_name2: "AWX-Collection-tests-tower_job_launch-jt2-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
proj_name: "AWX-Collection-tests-tower_job_launch-project-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Launch a Job Template
tower_job_launch:
job_template: "Demo Job Template"
register: result
- assert:
that:
- "result is changed"
- "result.status == 'pending'"
- name: Wait for a job template to complete
tower_job_wait:
job_id: "{{ result.id }}"
max_interval: 10
timeout: 120
register: result
- assert:
that:
- "result is not changed"
- "result.status == 'successful'"
- name: Check module fails with correct msg
tower_job_launch:
job_template: "Non_Existing_Job_Template"
inventory: "Demo Inventory"
register: result
ignore_errors: true
- assert:
that:
- "result is failed"
- "result is not changed"
- "'Non_Existing_Job_Template' in result.msg"
- name: Create a Job Template for testing prompt on launch
tower_job_template:
name: "{{ jt_name1 }}"
project: Demo Project
playbook: hello_world.yml
job_type: run
ask_credential: true
ask_inventory: true
state: present
register: result
- name: Launch job template with inventory and credential for prompt on launch
tower_job_launch:
job_template: "{{ jt_name1 }}"
inventory: "Demo Inventory"
credential: "Demo Credential"
register: result
- assert:
that:
- "result is changed"
- "result.status == 'pending'"
- name: Create a project for testing extra_vars
tower_project:
name: "{{ proj_name }}"
organization: Default
scm_type: git
scm_url: https://github.com/ansible/test-playbooks
- name: Create the job template with survey
tower_job_template:
name: "{{ jt_name2 }}"
project: "{{ proj_name }}"
playbook: debug.yml
job_type: run
state: present
inventory: "Demo Inventory"
survey_enabled: true
ask_variables_on_launch: false
survey_spec:
name: ''
description: ''
spec:
- question_name: Basic Name
question_description: Name
required: true
type: text
variable: basic_name
min: 0
max: 1024
default: ''
choices: ''
new_question: true
- question_name: Choose yes or no?
question_description: Choosing yes or no.
required: false
type: multiplechoice
variable: option_true_false
min:
max:
default: 'yes'
choices: |-
yes
no
new_question: true
- name: Kick off a job template with survey
tower_job_launch:
job_template: "{{ jt_name2 }}"
extra_vars:
basic_name: My First Variable
option_true_false: 'no'
ignore_errors: true
register: result
- assert:
that:
- result is not failed
- name: Prompt the job templates extra_vars on launch
tower_job_template:
name: "{{ jt_name2 }}"
state: present
ask_variables_on_launch: true
- name: Kick off a job template with extra_vars
tower_job_launch:
job_template: "{{ jt_name2 }}"
extra_vars:
basic_name: My First Variable
var1: My First Variable
var2: My Second Variable
ignore_errors: true
register: result
- assert:
that:
- result is not failed
- name: Create a Job Template for testing extra_vars
tower_job_template:
name: "{{ jt_name2 }}"
project: "{{ proj_name }}"
playbook: debug.yml
job_type: run
survey_enabled: false
state: present
inventory: "Demo Inventory"
extra_vars:
foo: bar
register: result
- name: Launch job template with inventory and credential for prompt on launch
tower_job_launch:
job_template: "{{ jt_name2 }}"
organization: Default
register: result
- assert:
that:
- "result is changed"
- name: Get the job
tower_job_list:
query: {"id": "{{result.id}}"}
register: result
- assert:
that:
- '{"foo": "bar"} | to_json in result.results[0].extra_vars'
- name: Delete the first jt
tower_job_template:
name: "{{ jt_name1 }}"
project: Demo Project
playbook: hello_world.yml
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Delete the second jt
tower_job_template:
name: "{{ jt_name2 }}"
project: "{{ proj_name }}"
playbook: debug.yml
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Delete the extra_vars project
tower_project:
name: "{{ proj_name }}"
organization: Default
state: absent
register: result
- assert:
that:
- "result is changed"
@@ -0,0 +1,38 @@
---
- name: Launch a Job Template
tower_job_launch:
job_template: "Demo Job Template"
register: job
- assert:
that:
- "job is changed"
- "job.status == 'pending'"
- name: List jobs w/ a matching primary key
tower_job_list:
query: {"id": "{{ job.id }}"}
register: matching_jobs
- assert:
that:
- "{{ matching_jobs.count }} == 1"
- name: List failed jobs (which don't exist)
tower_job_list:
status: failed
query: {"id": "{{ job.id }}"}
register: successful_jobs
- assert:
that:
- "{{ successful_jobs.count }} == 0"
- name: Get ALL result pages!
tower_job_list:
all_pages: true
register: all_page_query
- assert:
that:
- 'not all_page_query.next'
@@ -0,0 +1,378 @@
---
- name: Generate a random string for test
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: generate random string for project
set_fact:
cred1: "AWX-Collection-tests-tower_job_template-cred1-{{ test_id }}"
cred2: "AWX-Collection-tests-tower_job_template-cred2-{{ test_id }}"
cred3: "AWX-Collection-tests-tower_job_template-cred3-{{ test_id }}"
proj1: "AWX-Collection-tests-tower_job_template-proj-{{ test_id }}"
jt1: "AWX-Collection-tests-tower_job_template-jt1-{{ test_id }}"
jt2: "AWX-Collection-tests-tower_job_template-jt2-{{ test_id }}"
lab1: "AWX-Collection-tests-tower_job_template-lab1-{{ test_id }}"
email_not: "AWX-Collection-tests-tower_job_template-email-not-{{ test_id }}"
webhook_not: "AWX-Collection-tests-tower_notification_template-wehbook-not-{{ test_id }}"
- name: Create a Demo Project
tower_project:
name: "{{ proj1 }}"
organization: Default
state: present
scm_type: git
scm_url: https://github.com/ansible/ansible-tower-samples.git
register: proj_result
- name: Create Credential1
tower_credential:
name: "{{ cred1 }}"
organization: Default
kind: tower
register: cred1_result
- name: Create Credential2
tower_credential:
name: "{{ cred2 }}"
organization: Default
kind: ssh
- name: Create Credential3
tower_credential:
name: "{{ cred3 }}"
organization: Default
kind: ssh
- name: Create Label
tower_label:
name: "{{ lab1 }}"
organization: Default
- name: Add email notification
tower_notification_template:
name: "{{ email_not }}"
organization: Default
notification_type: email
username: user
password: s3cr3t
sender: tower@example.com
recipients:
- user1@example.com
host: smtp.example.com
port: 25
use_tls: false
use_ssl: false
state: present
- name: Add webhook notification
tower_notification_template:
name: "{{ webhook_not }}"
organization: Default
notification_type: webhook
url: http://www.example.com/hook
headers:
X-Custom-Header: value123
state: present
register: result
- name: Create Job Template 1
tower_job_template:
name: "{{ jt1 }}"
project: "{{ proj1 }}"
inventory: Demo Inventory
playbook: hello_world.yml
credentials: ["{{ cred1 }}", "{{ cred2 }}"]
job_type: run
state: present
register: jt1_result
- assert:
that:
- "jt1_result is changed"
- name: Add a credential to this JT
tower_job_template:
name: "{{ jt1 }}"
project: "{{ proj_result.id }}"
playbook: hello_world.yml
credentials:
- "{{ cred1_result.id }}"
register: result
- assert:
that:
- "result is changed"
- name: Try to add the same credential to this JT
tower_job_template:
name: "{{ jt1_result.id }}"
project: "{{ proj1 }}"
playbook: hello_world.yml
credentials:
- "{{ cred1 }}"
register: result
- assert:
that:
- "result is not changed"
- name: Add another credential to this JT
tower_job_template:
name: "{{ jt1 }}"
project: "{{ proj1 }}"
playbook: hello_world.yml
credentials:
- "{{ cred1 }}"
- "{{ cred2 }}"
register: result
- assert:
that:
- "result is changed"
- name: Remove a credential for this JT
tower_job_template:
name: "{{ jt1 }}"
project: "{{ proj1 }}"
playbook: hello_world.yml
credentials:
- "{{ cred1 }}"
register: result
- assert:
that:
- "result is changed"
- name: Remove all credentials from this JT
tower_job_template:
name: "{{ jt1 }}"
project: "{{ proj1 }}"
playbook: hello_world.yml
credentials: []
register: result
- assert:
that:
- "result is changed"
# This doesnt work if you include the credentials parameter
- name: Delete Job Template 1
tower_job_template:
name: "{{ jt1 }}"
playbook: hello_world.yml
job_type: run
project: "Does Not Exist"
inventory: "Does Not Exist"
webhook_credential: "Does Not Exist"
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Create Job Template 2
tower_job_template:
name: "{{ jt2 }}"
project: "{{ proj1 }}"
inventory: Demo Inventory
playbook: hello_world.yml
credential: "{{ cred3 }}"
job_type: run
labels:
- "{{ lab1 }}"
state: present
register: result
- assert:
that:
- "result is changed"
- name: Add survey to Job Template 2
tower_job_template:
name: "{{ jt2 }}"
survey_enabled: true
survey_spec:
name: ""
description: ""
spec:
- question_name: "Q1"
question_description: "The first question"
required: true
type: "text"
variable: "q1"
min: 5
max: 15
default: "hello"
register: result
- assert:
that:
- "result is changed"
- name: Re Add survey to Job Template 2
tower_job_template:
name: "{{ jt2 }}"
survey_enabled: true
survey_spec:
name: ""
description: ""
spec:
- question_name: "Q1"
question_description: "The first question"
required: true
type: "text"
variable: "q1"
min: 5
max: 15
default: "hello"
register: result
- assert:
that:
- "result is not changed"
- name: Add question to survey to Job Template 2
tower_job_template:
name: "{{ jt2 }}"
survey_enabled: true
survey_spec:
name: ""
description: ""
spec:
- question_name: "Q1"
question_description: "The first question"
required: true
type: "text"
variable: "q1"
min: 5
max: 15
default: "hello"
choices: ""
- question_name: "Q2"
type: "text"
variable: "q2"
required: false
register: result
- assert:
that:
- "result is changed"
- name: Remove survey from Job Template 2
tower_job_template:
name: "{{ jt2 }}"
survey_enabled: false
survey_spec: {}
register: result
- assert:
that:
- "result is changed"
- name: Add started notifications to Job Template 2
tower_job_template:
name: "{{ jt2 }}"
notification_templates_started:
- "{{ email_not }}"
- "{{ webhook_not }}"
register: result
- assert:
that:
- "result is changed"
- name: Re Add started notifications to Job Template 2
tower_job_template:
name: "{{ jt2 }}"
notification_templates_started:
- "{{ email_not }}"
- "{{ webhook_not }}"
register: result
- assert:
that:
- "result is not changed"
- name: Add success notifications to Job Template 2
tower_job_template:
name: "{{ jt2 }}"
notification_templates_success:
- "{{ email_not }}"
- "{{ webhook_not }}"
register: result
- assert:
that:
- "result is changed"
- name: Remove "on start" webhook notification from Job Template 2
tower_job_template:
name: "{{ jt2 }}"
notification_templates_started:
- "{{ email_not }}"
register: result
- assert:
that:
- "result is changed"
- name: Delete Job Template 2
tower_job_template:
name: "{{ jt2 }}"
project: "{{ proj1 }}"
inventory: Demo Inventory
playbook: hello_world.yml
credential: "{{ cred3 }}"
job_type: run
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Delete the Demo Project
tower_project:
name: "{{ proj1 }}"
organization: Default
state: absent
scm_type: git
scm_url: https://github.com/ansible/ansible-tower-samples.git
register: result
- name: Delete Credential1
tower_credential:
name: "{{ cred1 }}"
organization: Default
kind: tower
state: absent
- name: Delete Credential2
tower_credential:
name: "{{ cred2 }}"
organization: Default
kind: ssh
state: absent
- name: Delete Credential3
tower_credential:
name: "{{ cred3 }}"
organization: Default
kind: ssh
state: absent
# You can't delete a label directly so no cleanup needed
- name: Delete email notification
tower_notification_template:
name: "{{ email_not }}"
organization: Default
state: absent
- name: Delete webhook notification
tower_notification_template:
name: "{{ webhook_not }}"
organization: Default
state: absent
@@ -0,0 +1,183 @@
---
- name: Generate random string for template and project
set_fact:
jt_name: "AWX-Collection-tests-tower_job_wait-long_running-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
proj_name: "AWX-Collection-tests-tower_job_wait-long_running-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Assure that the demo project exists
tower_project:
name: "{{ proj_name }}"
scm_type: 'git'
scm_url: 'https://github.com/ansible/test-playbooks.git'
scm_update_on_launch: true
organization: Default
- name: Create a job template
tower_job_template:
name: "{{ jt_name }}"
playbook: "sleep.yml"
job_type: run
project: "{{ proj_name }}"
inventory: "Demo Inventory"
extra_vars:
sleep_interval: 300
- name: Check deprecation warnings
tower_job_wait:
min_interval: 10
max_interval: 20
job_id: "99999999"
register: result
ignore_errors: true
- assert:
that:
- "'Min and max interval have been deprecated, please use interval instead; interval will be set to 15'"
- name: Validate that interval superceeds min/max
tower_job_wait:
min_interval: 10
max_interval: 20
interval: 12
job_id: "99999999"
register: result
ignore_errors: true
- assert:
that:
- "result.msg =='Unable to wait on job 99999999; that ID does not exist in Tower.' or
'min and max interval have been depricated, please use interval instead, interval will be set to 12'"
- name: Check module fails with correct msg
tower_job_wait:
job_id: "99999999"
register: result
ignore_errors: true
- assert:
that:
- result is failed
- "result.msg =='Unable to wait, no job_id 99999999 found: The requested object could not be found.' or
'Unable to wait on job 99999999; that ID does not exist in Tower.'"
- name: Launch Demo Job Template (take happy path)
tower_job_launch:
job_template: "Demo Job Template"
register: job
- assert:
that:
- job is changed
- name: Wait for the Job to finish
tower_job_wait:
job_id: "{{ job.id }}"
register: wait_results
# Make sure it worked and that we have some data in our results
- assert:
that:
- wait_results is successful
- "'elapsed' in wait_results"
- "'id' in wait_results"
- name: Launch a long running job
tower_job_launch:
job_template: "{{ jt_name }}"
register: job
- assert:
that:
- job is changed
- name: Timeout waiting for the job to complete
tower_job_wait:
job_id: "{{ job.id }}"
timeout: 5
ignore_errors: true
register: wait_results
# Make sure that we failed and that we have some data in our results
- assert:
that:
- "wait_results.msg == 'Monitoring aborted due to timeout' or 'Timeout waiting for job to finish.'"
- "'id' in wait_results"
- name: Async cancel the long running job
tower_job_cancel:
job_id: "{{ job.id }}"
async: 3600
poll: 0
- name: Wait for the job to exit on cancel
tower_job_wait:
job_id: "{{ job.id }}"
register: wait_results
ignore_errors: true
- assert:
that:
- wait_results is failed
- 'wait_results.status == "canceled"'
- "wait_results.msg == 'Job with id {{ job.id }} failed' or 'Job with id={{ job.id }} failed, error: Job failed.'"
- name: Delete the job template
tower_job_template:
name: "{{ jt_name }}"
playbook: "sleep.yml"
job_type: run
project: "{{ proj_name }}"
inventory: "Demo Inventory"
state: absent
- name: Delete the project
tower_project:
name: "{{ proj_name }}"
organization: Default
state: absent
# tower workflow wait test
- name: Generate a random string for test
set_fact:
test_id1: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
when: test_id1 is not defined
- name: Generate names
set_fact:
wfjt_name2: "AWX-Collection-tests-tower_workflow_launch--wfjt1-{{ test_id1 }}"
- name: Create our workflow
tower_workflow_job_template:
name: "{{ wfjt_name2 }}"
state: present
- name: Add a node
tower_workflow_job_template_node:
workflow_job_template: "{{ wfjt_name2 }}"
unified_job_template: "Demo Job Template"
identifier: leaf
register: new_node
- name: Kick off a workflow
tower_workflow_launch:
workflow_template: "{{ wfjt_name2 }}"
ignore_errors: true
register: workflow
- name: Wait for the Workflow Job to finish
tower_job_wait:
job_id: "{{ workflow.job_info.id }}"
job_type: "workflow_jobs"
register: wait_workflow_results
# Make sure it worked and that we have some data in our results
- assert:
that:
- wait_workflow_results is successful
- "'elapsed' in wait_workflow_results"
- "'id' in wait_workflow_results"
- name: Clean up test workflow
tower_workflow_job_template:
name: "{{ wfjt_name2 }}"
state: absent
@@ -0,0 +1,27 @@
---
- name: Generate names
set_fact:
label_name: "AWX-Collection-tests-tower_label-label-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Create a Label
tower_label:
name: "{{ label_name }}"
organization: Default
state: present
- name: Check module fails with correct msg
tower_label:
name: "Test Label"
organization: "Non_existing_org"
state: present
register: result
ignore_errors: true
- assert:
that:
- "result is failed"
- "result is not changed"
- "'Non_existing_org' in result.msg"
- "result.total_results == 0"
# TODO: Deleting labels doesn't seem to work currently
@@ -0,0 +1,248 @@
---
- name: Generate a random string for test
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
when: test_id is not defined
- name: Generate usernames
set_fact:
usernames:
- "AWX-Collection-tests-tower_api_lookup-user1-{{ test_id }}"
- "AWX-Collection-tests-tower_api_lookup-user2-{{ test_id }}"
- "AWX-Collection-tests-tower_api_lookup-user3-{{ test_id }}"
hosts:
- "AWX-Collection-tests-tower_api_lookup-host1-{{ test_id }}"
- "AWX-Collection-tests-tower_api_lookup-host2-{{ test_id }}"
group_name: "AWX-Collection-tests-tower_api_lookup-group1-{{ test_id }}"
- name: Get our collection package
tower_meta:
register: tower_meta
- name: Generate the name of our plugin
set_fact:
plugin_name: "{{ tower_meta.prefix }}.tower_api"
- name: Create all of our users
tower_user:
username: "{{ item }}"
is_superuser: true
password: "{{ test_id }}"
loop: "{{ usernames }}"
register: user_creation_results
- block:
- name: Specify the connection params
debug:
msg: "{{ query(plugin_name, 'ping', host='DNE://junk.com', username='john', password='not_legit', verify_ssl=True) }}"
register: results
ignore_errors: true
- assert:
that:
- "'DNE' in results.msg"
- name: Create our hosts
tower_host:
name: "{{ item }}"
inventory: "Demo Inventory"
loop: "{{ hosts }}"
- name: Test too many params (failure from validation of terms)
set_fact:
junk: "{{ query(plugin_name, 'users', 'teams', query_params={}, ) }}"
ignore_errors: true
register: result
- assert:
that:
- result is failed
- "'You must pass exactly one endpoint to query' in result.msg"
- name: Try to load invalid endpoint
set_fact:
junk: "{{ query(plugin_name, 'john', query_params={}, ) }}"
ignore_errors: true
register: result
- assert:
that:
- result is failed
- "'The requested object could not be found at' in result.msg"
- name: Load user of a specific name without promoting objects
set_fact:
users_list: "{{ lookup(plugin_name, 'users', query_params={ 'username' : user_creation_results['results'][0]['item'] }, return_objects=False) }}"
- assert:
that:
- users_list['results'] | length() == 1
- users_list['count'] == 1
- users_list['results'][0]['id'] == user_creation_results['results'][0]['id']
- name: Load user of a specific name with promoting objects
set_fact:
user_objects: "{{ query(plugin_name, 'users', query_params={ 'username' : user_creation_results['results'][0]['item'] }, return_objects=True ) }}"
- assert:
that:
- user_objects | length() == 1
- users_list['results'][0]['id'] == user_objects[0]['id']
- name: Loop over one user with the loop syntax
assert:
that:
- item['id'] == user_creation_results['results'][0]['id']
loop: "{{ query(plugin_name, 'users', query_params={ 'username' : user_creation_results['results'][0]['item'] } ) }}"
loop_control:
label: "{{ item.id }}"
- name: Get a page of users as just ids
set_fact:
users: "{{ query(plugin_name, 'users', query_params={ 'username__endswith': test_id, 'page_size': 2 }, return_ids=True ) }}"
- name: Assert that user list has 2 ids only and that they are strings, not ints
assert:
that:
- users | length() == 2
- user_creation_results['results'][0]['id'] not in users
- user_creation_results['results'][0]['id'] | string in users
- name: Get all users of a system through next attribute
set_fact:
users: "{{ query(plugin_name, 'users', query_params={ 'username__endswith': test_id, 'page_size': 1 }, return_all=true ) }}"
- assert:
that:
- users | length() >= 3
- name: Get all of the users created with a max_objects of 1
set_fact:
users: "{{ lookup(plugin_name, 'users', query_params={ 'username__endswith': test_id, 'page_size': 1 }, return_all=true, max_objects=1 ) }}"
ignore_errors: true
register: max_user_errors
- assert:
that:
- max_user_errors is failed
- "'List view at users returned 3 objects, which is more than the maximum allowed by max_objects' in max_user_errors.msg"
- name: Get the ID of the first user created and verify that it is correct
assert:
that: "{{ query(plugin_name, 'users', query_params={ 'username' : user_creation_results['results'][0]['item'] }, return_ids=True)[0] }} == {{ user_creation_results['results'][0]['id'] }}"
- name: Try to get an ID of someone who does not exist
set_fact:
failed_user_id: "{{ query(plugin_name, 'users', query_params={ 'username': 'john jacob jingleheimer schmidt' }, expect_one=True) }}"
register: result
ignore_errors: true
- assert:
that:
- result is failed
- "'Expected one object from endpoint users' in result['msg']"
- name: Lookup too many users
set_fact:
too_many_user_ids: " {{ query(plugin_name, 'users', query_params={ 'username__endswith': test_id }, expect_one=True) }}"
register: results
ignore_errors: true
- assert:
that:
- results is failed
- "'Expected one object from endpoint users, but obtained 3' in results['msg']"
- name: Get the ping page
set_fact:
ping_data: "{{ lookup(plugin_name, 'ping' ) }}"
register: results
- assert:
that:
- results is succeeded
- "'active_node' in ping_data"
- name: "Make sure that expect_objects fails on an API page"
set_fact:
my_var: "{{ lookup(plugin_name, 'settings/ui', expect_objects=True) }}"
ignore_errors: true
register: results
- assert:
that:
- results is failed
- "'Did not obtain a list or detail view at settings/ui, and expect_objects or expect_one is set to True' in results.msg"
# DOCS Example Tests
- name: Load the UI settings
set_fact:
tower_settings: "{{ lookup('awx.awx.tower_api', 'settings/ui') }}"
- assert:
that:
- "'CUSTOM_LOGO' in tower_settings"
- name: Display the usernames of all admin users
debug:
msg: "Admin users: {{ query('awx.awx.tower_api', 'users', query_params={ 'is_superuser': true }) | map(attribute='username') | join(', ') }}"
register: results
- assert:
that:
- "'admin' in results.msg"
- name: debug all organizations in a loop # use query to return a list
debug:
msg: "Organization description={{ item['description'] }} id={{ item['id'] }}"
loop: "{{ query('awx.awx.tower_api', 'organizations') }}"
loop_control:
label: "{{ item['name'] }}"
- name: Make sure user 'john' is an org admin of the default org if the user exists
tower_role:
organization: Default
role: admin
user: "{{ usernames[0] }}"
state: absent
register: tower_role_revoke
when: "query('awx.awx.tower_api', 'users', query_params={ 'username': 'DNE_TESTING' }) | length == 1"
- assert:
that:
- tower_role_revoke is skipped
- name: Create an inventory group with all 'foo' hosts
tower_group:
name: "{{ group_name }}"
inventory: "Demo Inventory"
hosts: >-
{{ query(
'awx.awx.tower_api',
'hosts',
query_params={ 'name__endswith' : test_id, },
) | map(attribute='name') | list }}
register: group_creation
- assert:
that: group_creation is changed
always:
- name: Cleanup group
tower_group:
name: "{{ group_name }}"
inventory: "Demo Inventory"
state: absent
- name: Cleanup hosts
tower_host:
name: "{{ item }}"
inventory: "Demo Inventory"
state: absent
loop: "{{ hosts }}"
- name: Cleanup users
tower_user:
username: "{{ item }}"
state: absent
loop: "{{ usernames }}"
@@ -0,0 +1,230 @@
---
- name: Generate names
set_fact:
slack_not: "AWX-Collection-tests-tower_notification_template-slack-not-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
webhook_not: "AWX-Collection-tests-tower_notification_template-wehbook-not-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
email_not: "AWX-Collection-tests-tower_notification_template-email-not-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
twillo_not: "AWX-Collection-tests-tower_notification_template-twillo-not-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
pd_not: "AWX-Collection-tests-tower_notification_template-pd-not-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
irc_not: "AWX-Collection-tests-tower_notification_template-irc-not-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Test deprecation warnings with legacy name
tower_notification_template:
name: "{{ slack_not }}"
organization: Default
notification_type: slack
username: maw
sender: maw
recipients:
- everyone
use_tls: true
host: all
use_ssl: false
password: password
port: 12
channels:
- general
token: chunkecheese
account_token: asdf1234
from_number: "1 (888) 733-4281"
to_numbers:
- 867-5309
account_sid: vicious
subdomain: 'redhat.com'
service_key: skeleton
client_name: Bill
message_from: me
color: green
notify: true
url: ansible.com
headers:
X-Custom-Header: value123
server: littimer.somewhere.com
nickname: chalk
targets:
- zombie
state: absent
register: result
ignore_errors: true
- assert:
that:
- "'deprecations' in result"
# The 25 can be count from the size of the OLD_INPUT_NAMES list in the module
- result['deprecations'] | length() == 25
- name: Create Slack notification with custom messages
tower_notification_template:
name: "{{ slack_not }}"
organization: Default
notification_type: slack
token: a_token
channels:
- general
messages:
started:
message: "{{ '{{' }} job_friendly_name {{' }}' }} {{ '{{' }} job.id {{' }}' }} started"
success:
message: "{{ '{{' }} job_friendly_name {{ '}}' }} completed in {{ '{{' }} job.elapsed {{ '}}' }} seconds"
error:
message: "{{ '{{' }} job_friendly_name {{ '}}' }} FAILED! Please look at {{ '{{' }} job.url {{ '}}' }}"
state: present
register: result
- assert:
that:
- result is changed
- name: Delete Slack notification
tower_notification_template:
name: "{{ slack_not }}"
organization: Default
state: absent
register: result
- assert:
that:
- result is changed
- name: Add webhook notification
tower_notification_template:
name: "{{ webhook_not }}"
organization: Default
notification_type: webhook
url: http://www.example.com/hook
headers:
X-Custom-Header: value123
state: present
register: result
- assert:
that:
- result is changed
- name: Delete webhook notification
tower_notification_template:
name: "{{ webhook_not }}"
organization: Default
state: absent
register: result
- assert:
that:
- result is changed
- name: Add email notification
tower_notification_template:
name: "{{ email_not }}"
organization: Default
notification_type: email
username: user
password: s3cr3t
sender: tower@example.com
recipients:
- user1@example.com
host: smtp.example.com
port: 25
use_tls: false
use_ssl: false
state: present
register: result
- assert:
that:
- result is changed
- name: Delete email notification
tower_notification_template:
name: "{{ email_not }}"
organization: Default
state: absent
register: result
- assert:
that:
- result is changed
- name: Add twilio notification
tower_notification_template:
name: "{{ twillo_not }}"
organization: Default
notification_type: twilio
account_token: a_token
account_sid: a_sid
from_number: '+15551112222'
to_numbers:
- '+15553334444'
state: present
register: result
- assert:
that:
- result is changed
- name: Delete twilio notification
tower_notification_template:
name: "{{ twillo_not }}"
organization: Default
state: absent
register: result
- assert:
that:
- result is changed
- name: Add PagerDuty notification
tower_notification_template:
name: "{{ pd_not }}"
organization: Default
notification_type: pagerduty
token: a_token
subdomain: sub
client_name: client
service_key: a_key
state: present
register: result
- assert:
that:
- result is changed
- name: Delete PagerDuty notification
tower_notification_template:
name: "{{ pd_not }}"
organization: Default
state: absent
register: result
- assert:
that:
- result is changed
- name: Add IRC notification
tower_notification_template:
name: "{{ irc_not }}"
organization: Default
notification_type: irc
nickname: tower
password: s3cr3t
targets:
- user1
port: 8080
server: irc.example.com
use_ssl: false
state: present
register: result
- assert:
that:
- result is changed
- name: Delete IRC notification
tower_notification_template:
name: "{{ irc_not }}"
organization: Default
state: absent
register: result
- assert:
that:
- result is changed
@@ -0,0 +1,100 @@
---
- name: Generate an org name
set_fact:
org_name: "AWX-Collection-tests-tower_organization-org-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Make sure {{ org_name }} is not there
tower_organization:
name: "{{ org_name }}"
state: absent
register: result
- name: "Create a new organization"
tower_organization:
name: "{{ org_name }}"
galaxy_credentials:
- Ansible Galaxy
register: result
- assert:
that: "result is changed"
- name: "Make sure making the same org is not a change"
tower_organization:
name: "{{ org_name }}"
register: result
- assert:
that:
- "result is not changed"
- name: "Try adding a bad custom_virtualenv"
tower_organization:
name: "{{ org_name }}"
custom_virtualenv: "/does/not/exit"
register: result
ignore_errors: true
- assert:
that:
- "result is failed"
- name: "Pass in all parameters"
tower_organization:
name: "{{ org_name }}"
description: "A description"
custom_virtualenv: ""
register: result
- assert:
that:
- "result is changed"
- name: "Change the description"
tower_organization:
name: "{{ org_name }}"
description: "A new description"
custom_virtualenv: ""
register: result
- assert:
that:
- "result is changed"
- name: "Remove the organization"
tower_organization:
name: "{{ org_name }}"
state: absent
register: result
- assert:
that:
- "result is changed"
- name: "Remove a missing organization"
tower_organization:
name: "{{ org_name }}"
state: absent
register: result
- assert:
that:
- "result is not changed"
# Test behaviour common to all tower modules
- name: Check that SSL is available and verify_ssl is enabled (task must fail)
tower_organization:
name: Default
validate_certs: true
ignore_errors: true
register: check_ssl_is_used
- name: Check that connection failed
assert:
that:
- "'CERTIFICATE_VERIFY_FAILED' in check_ssl_is_used['msg']"
- name: Check that verify_ssl is disabled (task must not fail)
tower_organization:
name: Default
validate_certs: false
@@ -0,0 +1,252 @@
---
- name: Generate names
set_fact:
project_name1: "AWX-Collection-tests-tower_project-project1-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
project_name2: "AWX-Collection-tests-tower_project-project2-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
project_name3: "AWX-Collection-tests-tower_project-project3-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
jt1: "AWX-Collection-tests-tower_project-jt1-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
scm_cred_name: "AWX-Collection-tests-tower_project-scm-cred-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
org_name: "AWX-Collection-tests-tower_project-org-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
cred_name: "AWX-Collection-tests-tower_project-cred-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Create an SCM Credential
tower_credential:
name: "{{ scm_cred_name }}"
organization: Default
kind: scm
register: result
- assert:
that:
- result is changed
- name: Create a git project without credentials without waiting
tower_project:
name: "{{ project_name1 }}"
organization: Default
scm_type: git
scm_url: https://github.com/ansible/test-playbooks
wait: false
register: result
- assert:
that:
- result is changed
- name: Recreate the project to validate not changed
tower_project:
name: "{{ project_name1 }}"
organization: Default
scm_type: git
scm_url: https://github.com/ansible/test-playbooks
wait: true
register: result
- assert:
that:
- result is not changed
- name: Create organizations
tower_organization:
name: "{{ org_name }}"
register: result
- assert:
that:
- result is changed
- name: Create credential
tower_credential:
kind: scm
name: "{{ cred_name }}"
organization: "{{ org_name }}"
register: result
- assert:
that:
- result is changed
- name: Create a new test project in check_mode
tower_project:
name: "{{ project_name2 }}"
organization: "{{ org_name }}"
scm_type: git
scm_url: https://github.com/ansible/test-playbooks
scm_credential: "{{ cred_name }}"
check_mode: true
- name: Create a new test project
tower_project:
name: "{{ project_name2 }}"
organization: "{{ org_name }}"
scm_type: git
scm_url: https://github.com/ansible/test-playbooks
scm_credential: "{{ cred_name }}"
register: result
# If this fails it may be because the check_mode task actually already created
# the project, or it could be because the module actually failed somehow
- assert:
that:
- "result is changed"
- name: Check module fails with correct msg when given non-existing org as param
tower_project:
name: "{{ project_name2 }}"
organization: Non_Existing_Org
scm_type: git
scm_url: https://github.com/ansible/test-playbooks
scm_credential: "{{ cred_name }}"
register: result
ignore_errors: true
- assert:
that:
- "result is failed"
- "result is not changed"
- "'Non_Existing_Org' in result.msg"
- "result.total_results == 0"
- name: Check module fails with correct msg when given non-existing credential as param
tower_project:
name: "{{ project_name2 }}"
organization: "{{ org_name }}"
scm_type: git
scm_url: https://github.com/ansible/test-playbooks
scm_credential: Non_Existing_Credential
register: result
ignore_errors: true
- assert:
that:
- "result is failed"
- "result is not changed"
- "'Non_Existing_Credential' in result.msg"
- "result.total_results == 0"
- name: Create a git project without credentials without waiting
tower_project:
name: "{{ project_name3 }}"
organization: Default
scm_type: git
scm_branch: empty_branch
scm_url: https://github.com/ansible/test-playbooks
allow_override: true
register: result
- assert:
that:
- result is changed
- name: Update a git project, update the project and wait.
tower_project:
name: "{{ project_name3 }}"
organization: Default
scm_type: git
scm_branch: empty_branch
scm_url: https://github.com/ansible/test-playbooks
allow_override: true
wait: true
update_project: true
register: result
- name: Update a git project, update the project without waiting.
tower_project:
name: "{{ project_name3 }}"
organization: Default
scm_type: git
scm_branch: empty_branch
scm_url: https://github.com/ansible/test-playbooks
wait: false
update_project: true
register: result
- name: Create a job template that overrides the project scm_branch
tower_job_template:
name: "{{ jt1 }}"
project: "{{ project_name3 }}"
inventory: "Demo Inventory"
scm_branch: master
playbook: debug.yml
- name: Launch "{{ jt1 }}"
tower_job_launch:
job_template: "{{ jt1 }}"
register: result
- assert:
that:
- result is changed
- name: "wait for job {{ result.id }}"
tower_job_wait:
job_id: "{{ result.id }}"
register: job
- assert:
that:
- job is successful
- name: Delete the test job_template
tower_job_template:
name: "{{ jt1 }}"
project: "{{ project_name3 }}"
inventory: "Demo Inventory"
state: absent
- name: Delete the test project 3
tower_project:
name: "{{ project_name3 }}"
organization: Default
state: absent
- name: Delete the test project 2
tower_project:
name: "{{ project_name2 }}"
organization: "{{ org_name }}"
state: absent
- name: Delete the SCM Credential
tower_credential:
name: "{{ scm_cred_name }}"
organization: Default
kind: scm
state: absent
register: result
- assert:
that:
- result is changed
- name: Delete the test project 1
tower_project:
name: "{{ project_name1 }}"
organization: Default
state: absent
register: result
- assert:
that:
- result is changed
- name: Delete credential
tower_credential:
kind: scm
name: "{{ cred_name }}"
organization: "{{ org_name }}"
state: absent
register: result
- assert:
that:
- result is changed
- name: Delete the organization
tower_organization:
name: "{{ org_name }}"
state: absent
register: result
- assert:
that:
- result is changed
@@ -0,0 +1,58 @@
---
- name: get tower host variable
shell: tower-cli config host | cut -d ' ' -f2
register: host
- name: get tower username variable
shell: tower-cli config username | cut -d ' ' -f2
register: username
- name: get tower password variable
shell: tower-cli config password | cut -d ' ' -f2
register: password
- name: Fetch project_base_dir
uri:
url: "{{ host.stdout }}/api/v2/config/"
user: "{{ username.stdout }}"
password: "{{ password.stdout }}"
validate_certs: false
return_content: true
force_basic_auth: true
register: awx_config
- tower_inventory:
name: localhost
organization: Default
- tower_host:
name: localhost
inventory: localhost
variables:
ansible_connection: local
- name: create an unused SSH / Machine credential
tower_credential:
name: dummy
kind: ssh
ssh_key_data: |
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIIUl6R1xgzR6siIUArz4XBPtGZ09aetma2eWf1v3uYymoAoGCCqGSM49
AwEHoUQDQgAENJNjgeZDAh/+BY860s0yqrLDprXJflY0GvHIr7lX3ieCtrzOMCVU
QWzw35pc5tvuP34SSi0ZE1E+7cVMDDOF3w==
-----END EC PRIVATE KEY-----
organization: Default
- name: Disable bubblewrap
command: tower-cli setting modify AWX_PROOT_ENABLED false
- block:
- name: Create a directory for manual project
vars:
project_base_dir: "{{ awx_config.json.project_base_dir }}"
command: tower-cli ad_hoc launch --wait --inventory localhost
--credential dummy --module-name command
--module-args "mkdir -p {{ project_base_dir }}/{{ project_dir_name }}"
always:
- name: enable bubblewrap
command: tower-cli setting modify AWX_PROOT_ENABLED true
@@ -0,0 +1,37 @@
---
- name: generate random string for project
set_fact:
rand_string: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Generate manual project dir name
set_fact:
project_name: "manual project {{ rand_string }}"
- name: Generate manual project dir name
set_fact:
project_dir_name: "proj_{{ rand_string }}"
- name: create a project directory for manual project
import_tasks: create_project_dir.yml
- name: Create a manual project
tower_project:
name: "{{ project_name }}"
organization: Default
scm_type: manual
local_path: "{{ project_dir_name }}"
register: result
- assert:
that:
- "result is changed"
- name: Delete a manual project
tower_project:
name: "{{ project_name }}"
organization: Default
state: absent
register: result
- assert:
that:
- "result is changed"
@@ -0,0 +1,66 @@
---
- name: Generate a random string for test
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
when: test_id is not defined
- name: Generate names
set_fact:
project_name1: "AWX-Collection-tests-tower_project_update-project-{{ test_id }}"
- name: Create a git project without credentials without waiting
tower_project:
name: "{{ project_name1 }}"
organization: Default
scm_type: git
scm_url: https://github.com/ansible/test-playbooks
wait: false
register: project_create_result
- assert:
that:
- project_create_result is changed
- name: Update a project without waiting
tower_project_update:
name: "{{ project_name1 }}"
organization: Default
wait: false
register: result
- assert:
that:
- result is changed
- name: Update a project and wait
tower_project_update:
name: "{{ project_name1 }}"
organization: Default
wait: true
register: result
- assert:
that:
- result is successful
- name: Update a project by ID
tower_project_update:
name: "{{ project_create_result.id }}"
organization: Default
wait: true
register: result
- assert:
that:
- result is successful
- name: Delete the test project 1
tower_project:
name: "{{ project_name1 }}"
organization: Default
state: absent
register: result
- assert:
that:
- result is changed
@@ -0,0 +1,158 @@
---
- name: Generate a test id
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Generate names
set_fact:
username: "AWX-Collection-tests-tower_role-user-{{ test_id }}"
project_name: "AWX-Collection-tests-tower_role-project-1-{{ test_id }}"
jt1: "AWX-Collection-tests-tower_role-jt1-{{ test_id }}"
jt2: "AWX-Collection-tests-tower_role-jt2-{{ test_id }}"
wfjt_name: "AWX-Collection-tests-tower_role-project-wfjt-{{ test_id }}"
- block:
- name: Create a User
tower_user:
first_name: Joe
last_name: User
username: "{{ username }}"
password: "{{ 65535 | random | to_uuid }}"
email: joe@example.org
state: present
register: result
- assert:
that:
- "result is changed"
- name: Create a project
tower_project:
name: "{{ project_name }}"
organization: Default
scm_type: git
scm_url: https://github.com/ansible/test-playbooks
wait: true
register: project_info
- assert:
that:
- project_info is changed
- name: Create job templates
tower_job_template:
name: "{{ item }}"
project: "{{ project_name }}"
inventory: "Demo Inventory"
playbook: become.yml
with_items:
- jt1
- jt2
register: result
- assert:
that:
- "result is changed"
- name: Add Joe to the update role of the default Project with lookup Organization
tower_role:
user: "{{ username }}"
role: update
lookup_organization: Default
project: "Demo Project"
state: "{{ item }}"
register: result
with_items:
- "present"
- "absent"
- assert:
that:
- "result is changed"
- name: Add Joe to the new project by ID
tower_role:
user: "{{ username }}"
role: update
project: "{{ project_info['id'] }}"
state: "{{ item }}"
register: result
with_items:
- "present"
- "absent"
- assert:
that:
- "result is changed"
- name: Create a workflow
tower_workflow_job_template:
name: test-role-workflow
organization: Default
state: present
- name: Add Joe to workflow execute role
tower_role:
user: "{{ username }}"
role: execute
workflow: test-role-workflow
job_templates:
- jt1
- jt2
state: present
register: result
- assert:
that:
- "result is changed"
- name: Add Joe to workflow execute role, no-op
tower_role:
user: "{{ username }}"
role: execute
workflow: test-role-workflow
state: present
register: result
- assert:
that:
- "result is not changed"
- name: Add Joe to workflow approve role
tower_role:
user: "{{ username }}"
role: approval
workflow: test-role-workflow
state: present
register: result
- assert:
that:
- "result is changed"
always:
- name: Delete a User
tower_user:
username: "{{ username }}"
email: joe@example.org
state: absent
register: result
- name: Delete job templates
tower_job_template:
name: "{{ item }}"
project: "{{ project_name }}"
inventory: "Demo Inventory"
playbook: debug.yml
state: absent
with_items:
- jt1
- jt2
register: result
- name: Delete the project
tower_project:
name: "{{ project_name }}"
organization: Default
state: absent
register: result
@@ -0,0 +1,88 @@
---
- name: Generate a random string for test
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: generate random string for project
set_fact:
sched1: "AWX-Collection-tests-tower_schedule-sched1-{{ test_id }}"
- name: Try to create without an rrule
tower_schedule:
name: "{{ sched1 }}"
state: present
unified_job_template: "Demo Job Template"
enabled: true
register: result
ignore_errors: true
- assert:
that:
- result is failed
- "'Unable to create schedule {{ sched1 }}' in result.msg"
- name: Create with options that the JT does not support
tower_schedule:
name: "{{ sched1 }}"
state: present
unified_job_template: "Demo Job Template"
rrule: "DTSTART:20191219T130551Z RRULE:FREQ=WEEKLY;INTERVAL=1;COUNT=1"
description: "This hopefully will not work"
extra_data:
some: var
inventory: Demo Inventory
scm_branch: asdf1234
job_type: run
job_tags: other_tags
skip_tags: some_tags
limit: node1
diff_mode: true
verbosity: 4
enabled: true
register: result
ignore_errors: true
- assert:
that:
- result is failed
- "'Unable to create schedule {{ sched1 }}' in result.msg"
- name: Build a real schedule
tower_schedule:
name: "{{ sched1 }}"
state: present
unified_job_template: "Demo Job Template"
rrule: "DTSTART:20191219T130551Z RRULE:FREQ=WEEKLY;INTERVAL=1;COUNT=1"
register: result
- assert:
that:
- result is changed
- name: Rebuild the same schedule
tower_schedule:
name: "{{ sched1 }}"
state: present
unified_job_template: "Demo Job Template"
rrule: "DTSTART:20191219T130551Z RRULE:FREQ=WEEKLY;INTERVAL=1;COUNT=1"
register: result
- assert:
that:
- result is not changed
- name: Disable a schedule
tower_schedule:
name: "{{ sched1 }}"
state: present
enabled: "false"
register: result
- assert:
that:
- result is changed
- name: Delete the schedule
tower_schedule:
name: "{{ sched1 }}"
state: absent
@@ -0,0 +1,50 @@
---
- name: Get our collection package
tower_meta:
register: tower_meta
- name: Generate the name of our plugin
set_fact:
plugin_name: "{{ tower_meta.prefix }}.tower_schedule_rrule"
- name: Test too many params (failure from validation of terms)
debug:
msg: "{{ query(plugin_name, 'none', 'weekly', start_date='2020-4-16 03:45:07') }}"
ignore_errors: true
register: result
- assert:
that:
- result is failed
- "'You may only pass one schedule type in at a time' in result.msg"
- name: Test invalid frequency (failure from validation of term)
debug:
msg: "{{ query(plugin_name, 'john', start_date='2020-4-16 03:45:07') }}"
ignore_errors: true
register: result
- assert:
that:
- result is failed
- "'Frequency of john is invalid' in result.msg"
- name: Test an invalid start date (generic failure case from get_rrule)
debug:
msg: "{{ query(plugin_name, 'none', start_date='invalid') }}"
ignore_errors: true
register: result
- assert:
that:
- result is failed
- "'Parameter start_date must be in the format YYYY-MM-DD' in result.msg"
- name: Test end_on as count (generic success case)
debug:
msg: "{{ query(plugin_name, 'minute', start_date='2020-4-16 03:45:07', end_on='2') }}"
register: result
- assert:
that:
- result.msg == 'DTSTART;TZID=America/New_York:20200416T034507 RRULE:FREQ=MINUTELY;COUNT=2;INTERVAL=1'
@@ -0,0 +1,87 @@
---
- name: Set the value of AWX_PROOT_SHOW_PATHS to a baseline
tower_settings:
name: AWX_PROOT_SHOW_PATHS
value: '["/var/lib/awx/projects/"]'
- name: Set the value of AWX_PROOT_SHOW_PATHS to get an error back from Tower
tower_settings:
settings:
AWX_PROOT_SHOW_PATHS:
'not': 'a valid'
'tower': 'setting'
register: result
ignore_errors: true
- assert:
that:
- "result is failed"
- name: Set the value of AWX_PROOT_SHOW_PATHS
tower_settings:
name: AWX_PROOT_SHOW_PATHS
value: '["/var/lib/awx/projects/", "/tmp"]'
register: result
- assert:
that:
- "result is changed"
- name: Attempt to set the value of AWX_PROOT_BASE_PATH to what it already is
tower_settings:
name: AWX_PROOT_BASE_PATH
value: /tmp
register: result
- debug:
msg: "{{ result }}"
- assert:
that:
- "result is not changed"
- name: Apply a single setting via settings
tower_settings:
name: AWX_PROOT_SHOW_PATHS
value: '["/var/lib/awx/projects/", "/var/tmp"]'
register: result
- assert:
that:
- "result is changed"
- name: Apply multiple setting via settings with no change
tower_settings:
settings:
AWX_PROOT_BASE_PATH: /tmp
AWX_PROOT_SHOW_PATHS: ["/var/lib/awx/projects/", "/var/tmp"]
register: result
- debug:
msg: "{{ result }}"
- assert:
that:
- "result is not changed"
- name: Apply multiple setting via settings with change
tower_settings:
settings:
AWX_PROOT_BASE_PATH: /tmp
AWX_PROOT_SHOW_PATHS: []
register: result
- assert:
that:
- "result is changed"
- name: Handle an omit value
tower_settings:
name: AWX_PROOT_BASE_PATH
value: '{{ junk_var | default(omit) }}'
register: result
ignore_errors: true
- assert:
that:
- "'Unable to update settings' in result.msg"
@@ -0,0 +1,57 @@
---
- name: Generate names
set_fact:
team_name: "AWX-Collection-tests-tower_team-team-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Attempt to add a Tower team to a non-existant Organization
tower_team:
name: Test Team
organization: Missing_Organization
state: present
register: result
ignore_errors: true
- name: Assert a meaningful error was provided for the failed Tower team creation
assert:
that:
- "result is failed"
- "result is not changed"
- "'Missing_Organization' in result.msg"
- "result.total_results == 0"
- name: Create a Tower team
tower_team:
name: "{{ team_name }}"
organization: Default
register: result
- assert:
that:
- "result is changed"
- name: Delete a Tower team
tower_team:
name: "{{ team_name }}"
organization: Default
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Check module fails with correct msg
tower_team:
name: "{{ team_name }}"
organization: Non_Existing_Org
state: present
register: result
ignore_errors: true
- name: Lookup of the related organization should cause a failure
assert:
that:
- "result is failed"
- "result is not changed"
- "'Non_Existing_Org' in result.msg"
- "result.total_results == 0"
@@ -0,0 +1,110 @@
---
- name: Generate names
set_fact:
token_description: "AWX-Collection-tests-tower_token-description-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Try to use a token as a dict which is missing the token parameter
tower_job_list:
tower_oauthtoken:
not_token: "This has no token entry"
register: results
ignore_errors: true
- assert:
that:
- results is failed
- '"The provided dict in tower_oauthtoken did not properly contain the token entry" == results.msg'
- name: Try to use a token as a list
tower_job_list:
tower_oauthtoken:
- dummy_token
register: results
ignore_errors: true
- assert:
that:
- results is failed
- '"The provided tower_oauthtoken type was not valid (list). Valid options are str or dict." == results.msg'
- name: Try to delete a token with no existing_token or existing_token_id
tower_token:
state: absent
register: results
ignore_errors: true
- assert:
that:
- results is failed
# We don't assert a message here because it handled by ansible
- name: Try to delete a token with both existing_token or existing_token_id
tower_token:
existing_token:
id: 1234
existing_token_id: 1234
state: absent
register: results
ignore_errors: true
- assert:
that:
- results is failed
# We don't assert a message here because it handled by ansible
- block:
- name: Create a Token
tower_token:
description: '{{ token_description }}'
scope: "write"
state: present
register: new_token
- name: Validate our token works by token
tower_job_list:
tower_oauthtoken: "{{ tower_token.token }}"
register: job_list
- name: Validate out token works by object
tower_job_list:
tower_oauthtoken: "{{ tower_token }}"
register: job_list
always:
- name: Delete our Token with our own token
tower_token:
existing_token: "{{ tower_token }}"
tower_oauthtoken: "{{ tower_token }}"
state: absent
when: tower_token is defined
register: results
- assert:
that:
- results is changed or results is skipped
- block:
- name: Create a second token
tower_token:
description: '{{ token_description }}'
scope: "write"
state: present
register: results
- assert:
that:
- results is changed
always:
- name: Delete the second Token with our own token
tower_token:
existing_token_id: "{{ tower_token['id'] }}"
tower_oauthtoken: "{{ tower_token }}"
state: absent
when: tower_token is defined
register: results
- assert:
that:
- results is changed or resuslts is skipped
@@ -0,0 +1,120 @@
---
- name: Generate names
set_fact:
username: "AWX-Collection-tests-tower_user-user-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Create a User
tower_user:
username: "{{ username }}"
first_name: Joe
password: "{{ 65535 | random | to_uuid }}"
state: present
register: result
- assert:
that:
- "result is changed"
- name: Change a User by ID
tower_user:
username: "{{ result.id }}"
last_name: User
email: joe@example.org
state: present
register: result
- assert:
that:
- "result is changed"
- name: Check idempotency
tower_user:
username: "{{ username }}"
first_name: Joe
last_name: User
register: result
- assert:
that:
- "result is not changed"
- name: Delete a User
tower_user:
username: "{{ username }}"
email: joe@example.org
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Create an Auditor
tower_user:
first_name: Joe
last_name: Auditor
username: "{{ username }}"
password: "{{ 65535 | random | to_uuid }}"
email: joe@example.org
state: present
auditor: true
register: result
- assert:
that:
- "result is changed"
- name: Delete an Auditor
tower_user:
username: "{{ username }}"
email: joe@example.org
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Create a Superuser
tower_user:
first_name: Joe
last_name: Super
username: "{{ username }}"
password: "{{ 65535 | random | to_uuid }}"
email: joe@example.org
state: present
superuser: true
register: result
- assert:
that:
- "result is changed"
- name: Delete a Superuser
tower_user:
username: "{{ username }}"
email: joe@example.org
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Test tower SSL parameter
tower_user:
first_name: Joe
last_name: User
username: "{{ username }}"
password: "{{ 65535 | random | to_uuid }}"
email: joe@example.org
state: present
validate_certs: true
tower_host: http://foo.invalid
ignore_errors: true
register: result
- assert:
that:
- "'Unable to resolve tower_host' in result.msg or
'Can not verify ssl with non-https protocol' in result.exception"
@@ -0,0 +1,350 @@
---
- name: Generate a random string for names
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Generate random names for test objects
set_fact:
scm_cred_name: "AWX-Collection-tests-tower_workflow_job_template-scm-cred-{{ test_id }}"
demo_project_name: "AWX-Collection-tests-tower_workflow_job_template-proj-{{ test_id }}"
jt1_name: "AWX-Collection-tests-tower_workflow_job_template-jt1-{{ test_id }}"
jt2_name: "AWX-Collection-tests-tower_workflow_job_template-jt2-{{ test_id }}"
approval_node_name: "AWX-Collection-tests-tower_workflow_approval_node-{{ test_id }}"
lab1: "AWX-Collection-tests-tower_job_template-lab1-{{ test_id }}"
wfjt_name: "AWX-Collection-tests-tower_workflow_job_template-wfjt-{{ test_id }}"
email_not: "AWX-Collection-tests-tower_job_template-email-not-{{ test_id }}"
webhook_not: "AWX-Collection-tests-tower_notification_template-wehbook-not-{{ test_id }}"
- name: Create an SCM Credential
tower_credential:
name: "{{ scm_cred_name }}"
organization: Default
kind: scm
register: result
- assert:
that:
- "result is changed"
- name: Add email notification
tower_notification_template:
name: "{{ email_not }}"
organization: Default
notification_type: email
username: user
password: s3cr3t
sender: tower@example.com
recipients:
- user1@example.com
host: smtp.example.com
port: 25
use_tls: false
use_ssl: false
state: present
- name: Add webhook notification
tower_notification_template:
name: "{{ webhook_not }}"
organization: Default
notification_type: webhook
url: http://www.example.com/hook
headers:
X-Custom-Header: value123
state: present
register: result
- name: Create Label
tower_label:
name: "{{ lab1 }}"
organization: Default
- name: Create a Demo Project
tower_project:
name: "{{ demo_project_name }}"
organization: Default
state: present
scm_type: git
scm_url: https://github.com/ansible/ansible-tower-samples.git
scm_credential: "{{ scm_cred_name }}"
register: result
- assert:
that:
- "result is changed"
- name: Create a Job Template
tower_job_template:
name: "{{ jt1_name }}"
project: "{{ demo_project_name }}"
inventory: Demo Inventory
playbook: hello_world.yml
credential: Demo Credential
job_type: run
state: present
register: result
- assert:
that:
- "result is changed"
- name: Create a second Job Template
tower_job_template:
name: "{{ jt2_name }}"
project: "{{ demo_project_name }}"
inventory: Demo Inventory
playbook: hello_world.yml
credential: Demo Credential
job_type: run
state: present
register: result
- assert:
that:
- "result is changed"
- name: Add a Survey to second Job Template
tower_job_template:
name: "{{ jt2_name }}"
project: "{{ demo_project_name }}"
inventory: Demo Inventory
playbook: hello_world.yml
credential: Demo Credential
job_type: run
state: present
survey_enabled: true
survey_spec: '{"spec": [{"index": 0, "question_name": "my question?", "default": "mydef", "variable": "myvar", "type": "text", "required": false}], "description": "test", "name": "test"}'
register: result
- assert:
that:
- "result is changed"
- name: Create a workflow job template
tower_workflow_job_template:
name: "{{ wfjt_name }}"
inventory: Demo Inventory
extra_vars: {'foo': 'bar', 'another-foo': {'barz': 'bar2'}}
labels:
- "{{ lab1 }}"
register: result
- assert:
that:
- "result is changed"
# Node actions do what this schema command used to do
# schema: [{"success": [{"job_template": "{{ jt1_name }}"}], "job_template": "{{ jt2_name }}"}]
- name: Create leaf node
tower_workflow_job_template_node:
identifier: leaf
unified_job_template: "{{ jt2_name }}"
workflow: "{{ wfjt_name }}"
- name: Create root node
tower_workflow_job_template_node:
identifier: root
unified_job_template: "{{ jt1_name }}"
workflow: "{{ wfjt_name }}"
- name: Fail if no name is set for approval
tower_workflow_job_template_node:
identifier: approval_test
approval_node:
description: "{{ approval_node_name }}"
workflow: "{{ wfjt_name }}"
register: no_name_results
ignore_errors: true
- assert:
that:
- "no_name_results.msg == 'Approval node name is required to create approval node.'"
- name: Fail if absent and no identifier set
tower_workflow_job_template_node:
approval_node:
description: "{{ approval_node_name }}"
workflow: "{{ wfjt_name }}"
state: absent
register: no_identifier_results
ignore_errors: true
- assert:
that:
- "no_identifier_results.msg == 'missing required arguments: identifier'"
- name: Fail if present and no unified job template set
tower_workflow_job_template_node:
identifier: approval_test
workflow: "{{ wfjt_name }}"
register: no_unified_results
ignore_errors: true
- assert:
that:
- "no_unified_results.msg == 'state is present but any of the following are missing: unified_job_template, approval_node, success_nodes, always_nodes, failure_nodes'"
- name: Create approval node
tower_workflow_job_template_node:
identifier: approval_test
approval_node:
name: "{{ approval_node_name }}"
timeout: 900
workflow: "{{ wfjt_name }}"
- name: Create link for root node
tower_workflow_job_template_node:
identifier: root
workflow: "{{ wfjt_name }}"
success_nodes:
- approval_test
always_nodes:
- leaf
- name: Delete approval node
tower_workflow_job_template_node:
identifier: approval_test
approval_node:
name: "{{ approval_node_name }}"
state: absent
workflow: "{{ wfjt_name }}"
- name: Add started notifications to workflow job template
tower_workflow_job_template:
name: "{{ wfjt_name }}"
notification_templates_started:
- "{{ email_not }}"
- "{{ webhook_not }}"
register: result
- assert:
that:
- "result is changed"
- name: Re Add started notifications to workflow job template
tower_workflow_job_template:
name: "{{ wfjt_name }}"
notification_templates_started:
- "{{ email_not }}"
- "{{ webhook_not }}"
register: result
- assert:
that:
- "result is not changed"
- name: Add success notifications to workflow job template
tower_workflow_job_template:
name: "{{ wfjt_name }}"
notification_templates_success:
- "{{ email_not }}"
- "{{ webhook_not }}"
register: result
- assert:
that:
- "result is changed"
- name: Remove "on start" webhook notification from workflow job template
tower_workflow_job_template:
name: "{{ wfjt_name }}"
notification_templates_started:
- "{{ email_not }}"
register: result
- assert:
that:
- "result is changed"
- name: Delete a workflow job template with an invalid inventory and webook_credential
tower_workflow_job_template:
name: "{{ wfjt_name }}"
inventory: "Does Not Exist"
webhook_credential: "Does Not Exist"
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Check module fails with correct msg
tower_workflow_job_template:
name: "{{ wfjt_name }}"
organization: Non_Existing_Organization
register: result
ignore_errors: true
- assert:
that:
- "result is failed"
- "result is not changed"
- "'Non_Existing_Organization' in result.msg"
- "result.total_results == 0"
- name: Delete the Job Template
tower_job_template:
name: "{{ jt1_name }}"
project: "{{ demo_project_name }}"
inventory: Demo Inventory
playbook: hello_world.yml
credential: Demo Credential
job_type: run
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Delete the second Job Template
tower_job_template:
name: "{{ jt2_name }}"
project: "{{ demo_project_name }}"
inventory: Demo Inventory
playbook: hello_world.yml
credential: Demo Credential
job_type: run
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Delete the Demo Project
tower_project:
name: "{{ demo_project_name }}"
organization: Default
scm_type: git
scm_url: https://github.com/ansible/ansible-tower-samples.git
scm_credential: "{{ scm_cred_name }}"
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Delete the SCM Credential
tower_credential:
name: "{{ scm_cred_name }}"
organization: Default
kind: scm
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Delete email notification
tower_notification_template:
name: "{{ email_not }}"
organization: Default
state: absent
- name: Delete webhook notification
tower_notification_template:
name: "{{ webhook_not }}"
organization: Default
state: absent
@@ -0,0 +1,152 @@
---
- name: Generate a random string for test
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
when: test_id is not defined
- name: Generate names
set_fact:
wfjt_name1: "AWX-Collection-tests-tower_workflow_launch--wfjt1-{{ test_id }}"
- name: Create our workflow
tower_workflow_job_template:
name: "{{ wfjt_name1 }}"
state: present
- name: Add a node
tower_workflow_job_template_node:
workflow_job_template: "{{ wfjt_name1 }}"
unified_job_template: "Demo Job Template"
identifier: leaf
register: new_node
- name: Connect to Tower server but request an invalid workflow
tower_workflow_launch:
workflow_template: "Does Not Exist"
ignore_errors: true
register: result
- assert:
that:
- result is failed
- "'Unable to find workflow job template' in result.msg"
- name: Run the workflow without waiting (this should just give us back a job ID)
tower_workflow_launch:
workflow_template: "{{ wfjt_name1 }}"
wait: false
ignore_errors: true
register: result
- assert:
that:
- result is not failed
- "'id' in result['job_info']"
- name: Kick off a workflow and wait for it, but only for a second
tower_workflow_launch:
workflow_template: "{{ wfjt_name1 }}"
timeout: 1
ignore_errors: true
register: result
- assert:
that:
- result is failed
- "'Monitoring of Workflow Job - {{ wfjt_name1 }} aborted due to timeout' in result.msg"
- name: Kick off a workflow and wait for it
tower_workflow_launch:
workflow_template: "{{ wfjt_name1 }}"
ignore_errors: true
register: result
- assert:
that:
- result is not failed
- "'id' in result['job_info']"
- name: Kick off a workflow with extra_vars but not enabled
tower_workflow_launch:
workflow_template: "{{ wfjt_name1 }}"
extra_vars:
var1: My First Variable
var2: My Second Variable
ignore_errors: true
register: result
- assert:
that:
- result is failed
- "'The field extra_vars was specified but the workflow job template does not allow for it to be overridden' in result.errors"
- name: Prompt the workflow's with survey
tower_workflow_job_template:
name: "{{ wfjt_name1 }}"
state: present
survey_enabled: true
ask_variables_on_launch: false
survey:
name: ''
description: ''
spec:
- question_name: Basic Name
question_description: Name
required: true
type: text
variable: basic_name
min: 0
max: 1024
default: ''
choices: ''
new_question: true
- question_name: Choose yes or no?
question_description: Choosing yes or no.
required: false
type: multiplechoice
variable: option_true_false
min:
max:
default: 'yes'
choices: |-
yes
no
new_question: true
- name: Kick off a workflow with survey
tower_workflow_launch:
workflow_template: "{{ wfjt_name1 }}"
extra_vars:
basic_name: My First Variable
option_true_false: 'no'
ignore_errors: true
register: result
- assert:
that:
- result is not failed
- name: Prompt the workflow's extra_vars on launch
tower_workflow_job_template:
name: "{{ wfjt_name1 }}"
state: present
ask_variables_on_launch: true
- name: Kick off a workflow with extra_vars
tower_workflow_launch:
workflow_template: "{{ wfjt_name1 }}"
extra_vars:
basic_name: My First Variable
var1: My First Variable
var2: My Second Variable
ignore_errors: true
register: result
- assert:
that:
- result is not failed
- name: Clean up test workflow
tower_workflow_job_template:
name: "{{ wfjt_name1 }}"
state: absent