mirror of
https://github.com/ansible/awx.git
synced 2026-05-10 10:57:35 -02:30
ansible_tower: Add custom_virtualenv attribute when applicable (#60200)
In Ansible Tower/AWX, there are three kinds of objects that can be tied to custom python virtual environment: - job template - project - organization This patch updates the three ansible modules that creates those objects so that the 'custom_virtualenv' attribute can be set if specified. Testing Done: via a playbook, test organization, projet then template creation without any 'custom_virtualenv' attribute specified. Check that the resources get created and that their python env is set to default. Then re-do the same test but this time with the 'custom_virtualenv' attribute specified. Ensure in AWX UI that those resources have the right 'custom_virtualenv' set.
This commit is contained in:
committed by
AlanCoding
parent
85d5387f31
commit
a026838f77
@@ -191,6 +191,13 @@ options:
|
|||||||
description:
|
description:
|
||||||
- Maximum time in seconds to wait for a job to finish (server-side).
|
- Maximum time in seconds to wait for a job to finish (server-side).
|
||||||
type: int
|
type: int
|
||||||
|
custom_virtualenv:
|
||||||
|
version_added: "2.9"
|
||||||
|
description:
|
||||||
|
- Local absolute file path containing a custom Python virtualenv to use.
|
||||||
|
type: str
|
||||||
|
required: False
|
||||||
|
default: ''
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- Desired state of the resource.
|
- Desired state of the resource.
|
||||||
@@ -218,6 +225,7 @@ EXAMPLES = '''
|
|||||||
tower_config_file: "~/tower_cli.cfg"
|
tower_config_file: "~/tower_cli.cfg"
|
||||||
survey_enabled: yes
|
survey_enabled: yes
|
||||||
survey_spec: "{{ lookup('file', 'my_survey.json') }}"
|
survey_spec: "{{ lookup('file', 'my_survey.json') }}"
|
||||||
|
custom_virtualenv: "/var/lib/awx/venv/custom-venv/"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ..module_utils.ansible_tower import TowerModule, tower_auth_config, tower_check_mode
|
from ..module_utils.ansible_tower import TowerModule, tower_auth_config, tower_check_mode
|
||||||
@@ -298,6 +306,7 @@ def main():
|
|||||||
playbook=dict(required=True),
|
playbook=dict(required=True),
|
||||||
credential=dict(default=''),
|
credential=dict(default=''),
|
||||||
vault_credential=dict(default=''),
|
vault_credential=dict(default=''),
|
||||||
|
custom_virtualenv=dict(type='str', required=False, default=''),
|
||||||
forks=dict(type='int'),
|
forks=dict(type='int'),
|
||||||
limit=dict(default=''),
|
limit=dict(default=''),
|
||||||
verbosity=dict(type='int', choices=[0, 1, 2, 3, 4], default=0),
|
verbosity=dict(type='int', choices=[0, 1, 2, 3, 4], default=0),
|
||||||
|
|||||||
@@ -32,6 +32,13 @@ options:
|
|||||||
description:
|
description:
|
||||||
- The description to use for the organization.
|
- The description to use for the organization.
|
||||||
type: str
|
type: str
|
||||||
|
custom_virtualenv:
|
||||||
|
version_added: "2.9"
|
||||||
|
description:
|
||||||
|
- Local absolute file path containing a custom Python virtualenv to use.
|
||||||
|
type: str
|
||||||
|
required: False
|
||||||
|
default: ''
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- Desired state of the resource.
|
- Desired state of the resource.
|
||||||
@@ -49,6 +56,14 @@ EXAMPLES = '''
|
|||||||
description: "Foo bar organization"
|
description: "Foo bar organization"
|
||||||
state: present
|
state: present
|
||||||
tower_config_file: "~/tower_cli.cfg"
|
tower_config_file: "~/tower_cli.cfg"
|
||||||
|
|
||||||
|
- name: Create tower organization using 'foo-venv' as default Python virtualenv
|
||||||
|
tower_organization:
|
||||||
|
name: "Foo"
|
||||||
|
description: "Foo bar organization using foo-venv"
|
||||||
|
custom_virtualenv: "/var/lib/awx/venv/foo-venv/"
|
||||||
|
state: present
|
||||||
|
tower_config_file: "~/tower_cli.cfg"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ..module_utils.ansible_tower import TowerModule, tower_auth_config, tower_check_mode
|
from ..module_utils.ansible_tower import TowerModule, tower_auth_config, tower_check_mode
|
||||||
@@ -66,6 +81,7 @@ def main():
|
|||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
name=dict(required=True),
|
name=dict(required=True),
|
||||||
description=dict(),
|
description=dict(),
|
||||||
|
custom_virtualenv=dict(type='str', required=False, default=''),
|
||||||
state=dict(choices=['present', 'absent'], default='present'),
|
state=dict(choices=['present', 'absent'], default='present'),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -73,6 +89,7 @@ def main():
|
|||||||
|
|
||||||
name = module.params.get('name')
|
name = module.params.get('name')
|
||||||
description = module.params.get('description')
|
description = module.params.get('description')
|
||||||
|
custom_virtualenv = module.params.get('custom_virtualenv')
|
||||||
state = module.params.get('state')
|
state = module.params.get('state')
|
||||||
|
|
||||||
json_output = {'organization': name, 'state': state}
|
json_output = {'organization': name, 'state': state}
|
||||||
@@ -83,7 +100,7 @@ def main():
|
|||||||
organization = tower_cli.get_resource('organization')
|
organization = tower_cli.get_resource('organization')
|
||||||
try:
|
try:
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
result = organization.modify(name=name, description=description, create_on_missing=True)
|
result = organization.modify(name=name, description=description, custom_virtualenv=custom_virtualenv, create_on_missing=True)
|
||||||
json_output['id'] = result['id']
|
json_output['id'] = result['id']
|
||||||
elif state == 'absent':
|
elif state == 'absent':
|
||||||
result = organization.delete(name=name)
|
result = organization.delete(name=name)
|
||||||
|
|||||||
@@ -87,6 +87,8 @@ options:
|
|||||||
description:
|
description:
|
||||||
- Local absolute file path containing a custom Python virtualenv to use
|
- Local absolute file path containing a custom Python virtualenv to use
|
||||||
type: str
|
type: str
|
||||||
|
required: False
|
||||||
|
default: ''
|
||||||
organization:
|
organization:
|
||||||
description:
|
description:
|
||||||
- Primary key of organization for project.
|
- Primary key of organization for project.
|
||||||
@@ -156,7 +158,7 @@ def main():
|
|||||||
scm_update_on_launch=dict(type='bool', default=False),
|
scm_update_on_launch=dict(type='bool', default=False),
|
||||||
scm_update_cache_timeout=dict(type='int'),
|
scm_update_cache_timeout=dict(type='int'),
|
||||||
job_timeout=dict(type='int', default=0),
|
job_timeout=dict(type='int', default=0),
|
||||||
custom_virtualenv=dict(),
|
custom_virtualenv=dict(type='str', required=False, default=''),
|
||||||
local_path=dict(),
|
local_path=dict(),
|
||||||
state=dict(choices=['present', 'absent'], default='present'),
|
state=dict(choices=['present', 'absent'], default='present'),
|
||||||
wait=dict(type='bool', default=True),
|
wait=dict(type='bool', default=True),
|
||||||
|
|||||||
Reference in New Issue
Block a user