mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 14:57:39 -02:30
Using execution_environment option in ad_hoc_command module (#14105)
This commit is contained in:
@@ -145,6 +145,7 @@ def main():
|
|||||||
wait = module.params.get('wait')
|
wait = module.params.get('wait')
|
||||||
interval = module.params.get('interval')
|
interval = module.params.get('interval')
|
||||||
timeout = module.params.get('timeout')
|
timeout = module.params.get('timeout')
|
||||||
|
execution_environment = module.params.get('execution_environment')
|
||||||
|
|
||||||
# Create a datastructure to pass into our command launch
|
# Create a datastructure to pass into our command launch
|
||||||
post_data = {
|
post_data = {
|
||||||
@@ -158,6 +159,8 @@ def main():
|
|||||||
# Attempt to look up the related items the user specified (these will fail the module if not found)
|
# Attempt to look up the related items the user specified (these will fail the module if not found)
|
||||||
post_data['inventory'] = module.resolve_name_to_id('inventories', inventory)
|
post_data['inventory'] = module.resolve_name_to_id('inventories', inventory)
|
||||||
post_data['credential'] = module.resolve_name_to_id('credentials', credential)
|
post_data['credential'] = module.resolve_name_to_id('credentials', credential)
|
||||||
|
if execution_environment:
|
||||||
|
post_data['execution_environment'] = module.resolve_name_to_id('execution_environments', execution_environment)
|
||||||
|
|
||||||
# Launch the ad hoc command
|
# Launch the ad hoc command
|
||||||
results = module.post_endpoint('ad_hoc_commands', **{'data': post_data})
|
results = module.post_endpoint('ad_hoc_commands', **{'data': post_data})
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
inv_name: "AWX-Collection-tests-ad_hoc_command-inventory-{{ test_id }}"
|
inv_name: "AWX-Collection-tests-ad_hoc_command-inventory-{{ test_id }}"
|
||||||
ssh_cred_name: "AWX-Collection-tests-ad_hoc_command-ssh-cred-{{ test_id }}"
|
ssh_cred_name: "AWX-Collection-tests-ad_hoc_command-ssh-cred-{{ test_id }}"
|
||||||
org_name: "AWX-Collection-tests-ad_hoc_command-org-{{ test_id }}"
|
org_name: "AWX-Collection-tests-ad_hoc_command-org-{{ test_id }}"
|
||||||
|
ee_name: "AWX-Collection-tests-ad_hoc_command-ee-{{ test_id }}"
|
||||||
|
|
||||||
- name: Create a New Organization
|
- name: Create a New Organization
|
||||||
organization:
|
organization:
|
||||||
@@ -34,6 +35,16 @@
|
|||||||
credential_type: 'Machine'
|
credential_type: 'Machine'
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
|
- name: Create an Execution Environment
|
||||||
|
execution_environment:
|
||||||
|
name: "{{ ee_name }}"
|
||||||
|
organization: "{{ org_name }}"
|
||||||
|
description: "EE for Testing"
|
||||||
|
image: quay.io/ansible/awx-ee
|
||||||
|
pull: always
|
||||||
|
state: present
|
||||||
|
register: result_ee
|
||||||
|
|
||||||
- name: Launch an Ad Hoc Command waiting for it to finish
|
- name: Launch an Ad Hoc Command waiting for it to finish
|
||||||
ad_hoc_command:
|
ad_hoc_command:
|
||||||
inventory: "{{ inv_name }}"
|
inventory: "{{ inv_name }}"
|
||||||
@@ -61,6 +72,21 @@
|
|||||||
- "result is changed"
|
- "result is changed"
|
||||||
- "result.status == 'successful'"
|
- "result.status == 'successful'"
|
||||||
|
|
||||||
|
- name: Launch an Ad Hoc Command with Execution Environment specified
|
||||||
|
ad_hoc_command:
|
||||||
|
inventory: "Demo Inventory"
|
||||||
|
credential: "{{ ssh_cred_name }}"
|
||||||
|
execution_environment: "{{ ee_name }}"
|
||||||
|
module_name: "ping"
|
||||||
|
wait: true
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "result is changed"
|
||||||
|
- "result.status == 'successful'"
|
||||||
|
- "lookup('awx.awx.controller_api', 'ad_hoc_commands/' ~ result.id)['execution_environment'] == result_ee.id"
|
||||||
|
|
||||||
- name: Check module fails with correct msg
|
- name: Check module fails with correct msg
|
||||||
ad_hoc_command:
|
ad_hoc_command:
|
||||||
inventory: "{{ inv_name }}"
|
inventory: "{{ inv_name }}"
|
||||||
@@ -75,6 +101,13 @@
|
|||||||
- "result is not changed"
|
- "result is not changed"
|
||||||
- "'Does not exist' in result.response['json']['module_name'][0]"
|
- "'Does not exist' in result.response['json']['module_name'][0]"
|
||||||
|
|
||||||
|
- name: Delete the Execution Environment
|
||||||
|
execution_environment:
|
||||||
|
name: "{{ ee_name }}"
|
||||||
|
organization: "{{ org_name }}"
|
||||||
|
image: quay.io/ansible/awx-ee
|
||||||
|
state: absent
|
||||||
|
|
||||||
- name: Delete the Credential
|
- name: Delete the Credential
|
||||||
credential:
|
credential:
|
||||||
name: "{{ ssh_cred_name }}"
|
name: "{{ ssh_cred_name }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user