Initial commit of ad hoc module

This commit is contained in:
John Westcott IV
2020-09-24 10:20:00 -04:00
parent acc0ba570e
commit baf3b617cb
9 changed files with 690 additions and 1 deletions

View File

@@ -0,0 +1,37 @@
---
#- 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:
# proj_name: "AWX-Collection-tests-tower_job_launch-project-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Launch an Ad Hoc Command waiting for it to finish
tower_ad_hoc_command:
inventory: "Demo Inventory"
credential: "Demo Credential"
module_name: "command"
module_args: "echo I<3 Ansible"
wait: True
register: result
- assert:
that:
- "result is changed"
- "result.status == 'successful'"
- name: Check module fails with correct msg
tower_ad_hoc_command:
inventory: "Demo Inventory"
credential: "Demo Credential"
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]"

View File

@@ -0,0 +1,63 @@
---
#- 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:
# proj_name: "AWX-Collection-tests-tower_job_launch-project-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Launch an Ad Hoc Command
tower_ad_hoc_command:
inventory: "Demo Inventory"
credential: "Demo Credential"
module_name: "command"
module_args: "sleep 10"
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
tower_ad_hoc_command_cancel:
command_id: "{{ command.id }}"
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'"

View File

@@ -0,0 +1,87 @@
---
#- 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:
# proj_name: "AWX-Collection-tests-tower_job_launch-project-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- 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: "Demo Inventory"
credential: "Demo Credential"
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: "Demo Inventory"
credential: "Demo Credential"
module_name: "command"
module_args: "sleep 100"
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:
- "wait_results.msg == 'Monitoring aborted due to timeout' or 'Timeout waiting for command to finish.'"
- "'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'"