mirror of
https://github.com/ansible/awx.git
synced 2026-02-24 06:26:00 -03:30
tower_username to controller_username, etc
This commit is contained in:
@@ -13,44 +13,49 @@ class ModuleDocFragment(object):
|
||||
# Automation Platform Controller documentation fragment
|
||||
DOCUMENTATION = r'''
|
||||
options:
|
||||
tower_host:
|
||||
controller_host:
|
||||
description:
|
||||
- URL to your Automation Platform Controller instance.
|
||||
- If value not set, will try environment variable C(TOWER_HOST) and then config files
|
||||
- If value not set, will try environment variable C(CONTROLLER_HOST) and then config files
|
||||
- If value not specified by any means, the value of C(127.0.0.1) will be used
|
||||
type: str
|
||||
tower_username:
|
||||
aliases: [ tower_host ]
|
||||
controller_username:
|
||||
description:
|
||||
- Username for your controller instance.
|
||||
- If value not set, will try environment variable C(TOWER_USERNAME) and then config files
|
||||
- If value not set, will try environment variable C(CONTROLLER_USERNAME) and then config files
|
||||
type: str
|
||||
tower_password:
|
||||
aliases: [ tower_username ]
|
||||
controller_password:
|
||||
description:
|
||||
- Password for your controller instance.
|
||||
- If value not set, will try environment variable C(TOWER_PASSWORD) and then config files
|
||||
- If value not set, will try environment variable C(CONTROLLER_PASSWORD) and then config files
|
||||
type: str
|
||||
tower_oauthtoken:
|
||||
aliases: [ tower_password ]
|
||||
controller_oauthtoken:
|
||||
description:
|
||||
- The OAuth token to use.
|
||||
- This value can be in one of two formats.
|
||||
- A string which is the token itself. (i.e. bqV5txm97wqJqtkxlMkhQz0pKhRMMX)
|
||||
- A dictionary structure as returned by the token module.
|
||||
- If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files
|
||||
- If value not set, will try environment variable C(CONTROLLER_OAUTH_TOKEN) and then config files
|
||||
type: raw
|
||||
version_added: "3.7"
|
||||
aliases: [ tower_oauthtoken ]
|
||||
validate_certs:
|
||||
description:
|
||||
- Whether to allow insecure connections to AWX.
|
||||
- If C(no), SSL certificates will not be validated.
|
||||
- This should only be used on personally controlled sites using self-signed certificates.
|
||||
- If value not set, will try environment variable C(TOWER_VERIFY_SSL) and then config files
|
||||
- If value not set, will try environment variable C(CONTROLLER_VERIFY_SSL) and then config files
|
||||
type: bool
|
||||
aliases: [ tower_verify_ssl ]
|
||||
tower_config_file:
|
||||
controller_config_file:
|
||||
description:
|
||||
- Path to the controller config file.
|
||||
- If provided, the other locations for config files will not be considered.
|
||||
type: path
|
||||
aliases: [tower_config_file]
|
||||
|
||||
notes:
|
||||
- If no I(config_file) is provided we will attempt to use the tower-cli library
|
||||
|
||||
@@ -16,27 +16,27 @@ options:
|
||||
host:
|
||||
description: The network address of your Automation Platform Controller host.
|
||||
env:
|
||||
- name: TOWER_HOST
|
||||
- name: CONTROLLER_HOST
|
||||
username:
|
||||
description: The user that you plan to use to access inventories on the controller.
|
||||
env:
|
||||
- name: TOWER_USERNAME
|
||||
- name: CONTROLLER_USERNAME
|
||||
password:
|
||||
description: The password for your controller user.
|
||||
env:
|
||||
- name: TOWER_PASSWORD
|
||||
- name: CONTROLLER_PASSWORD
|
||||
oauth_token:
|
||||
description:
|
||||
- The OAuth token to use.
|
||||
env:
|
||||
- name: TOWER_OAUTH_TOKEN
|
||||
- name: CONTROLLER_OAUTH_TOKEN
|
||||
verify_ssl:
|
||||
description:
|
||||
- Specify whether Ansible should verify the SSL certificate of the controller host.
|
||||
- Defaults to True, but this is handled by the shared module_utils code
|
||||
type: bool
|
||||
env:
|
||||
- name: TOWER_VERIFY_SSL
|
||||
- name: CONTROLLER_VERIFY_SSL
|
||||
aliases: [ validate_certs ]
|
||||
|
||||
notes:
|
||||
|
||||
@@ -32,19 +32,19 @@ class ItemNotDefined(Exception):
|
||||
class ControllerModule(AnsibleModule):
|
||||
url = None
|
||||
AUTH_ARGSPEC = dict(
|
||||
tower_host=dict(required=False, fallback=(env_fallback, ['CONTROLLER_HOST', 'TOWER_HOST'])),
|
||||
tower_username=dict(required=False, fallback=(env_fallback, ['CONTROLLER_USERNAME', 'TOWER_USERNAME'])),
|
||||
tower_password=dict(no_log=True, required=False, fallback=(env_fallback, ['CONTROLLER_PASSWORD', 'TOWER_PASSWORD'])),
|
||||
controller_host=dict(required=False, fallback=(env_fallback, ['CONTROLLER_HOST', 'TOWER_HOST'])),
|
||||
controller_username=dict(required=False, fallback=(env_fallback, ['CONTROLLER_USERNAME', 'TOWER_USERNAME'])),
|
||||
controller_password=dict(no_log=True, required=False, fallback=(env_fallback, ['CONTROLLER_PASSWORD', 'TOWER_PASSWORD'])),
|
||||
validate_certs=dict(type='bool', aliases=['tower_verify_ssl'], required=False, fallback=(env_fallback, ['CONTROLLER_VERIFY_SSL', 'TOWER_VERIFY_SSL'])),
|
||||
tower_oauthtoken=dict(type='raw', no_log=True, required=False, fallback=(env_fallback, ['CONTROLLER_OAUTH_TOKEN', 'TOWER_OAUTH_TOKEN'])),
|
||||
tower_config_file=dict(type='path', required=False, default=None),
|
||||
controller_oauthtoken=dict(type='raw', no_log=True, required=False, fallback=(env_fallback, ['CONTROLLER_OAUTH_TOKEN', 'TOWER_OAUTH_TOKEN'])),
|
||||
controller_config_file=dict(type='path', required=False, default=None),
|
||||
)
|
||||
short_params = {
|
||||
'host': 'tower_host',
|
||||
'username': 'tower_username',
|
||||
'password': 'tower_password',
|
||||
'host': 'controller_host',
|
||||
'username': 'controller_username',
|
||||
'password': 'controller_password',
|
||||
'verify_ssl': 'validate_certs',
|
||||
'oauth_token': 'tower_oauthtoken',
|
||||
'oauth_token': 'controller_oauthtoken',
|
||||
}
|
||||
host = '127.0.0.1'
|
||||
username = None
|
||||
@@ -82,18 +82,18 @@ class ControllerModule(AnsibleModule):
|
||||
if direct_value is not None:
|
||||
setattr(self, short_param, direct_value)
|
||||
|
||||
# Perform magic depending on whether tower_oauthtoken is a string or a dict
|
||||
if self.params.get('tower_oauthtoken'):
|
||||
token_param = self.params.get('tower_oauthtoken')
|
||||
# Perform magic depending on whether controller_oauthtoken is a string or a dict
|
||||
if self.params.get('controller_oauthtoken'):
|
||||
token_param = self.params.get('controller_oauthtoken')
|
||||
if type(token_param) is dict:
|
||||
if 'token' in token_param:
|
||||
self.oauth_token = self.params.get('tower_oauthtoken')['token']
|
||||
self.oauth_token = self.params.get('controller_oauthtoken')['token']
|
||||
else:
|
||||
self.fail_json(msg="The provided dict in tower_oauthtoken did not properly contain the token entry")
|
||||
self.fail_json(msg="The provided dict in controller_oauthtoken did not properly contain the token entry")
|
||||
elif isinstance(token_param, string_types):
|
||||
self.oauth_token = self.params.get('tower_oauthtoken')
|
||||
self.oauth_token = self.params.get('controller_oauthtoken')
|
||||
else:
|
||||
error_msg = "The provided tower_oauthtoken type was not valid ({0}). Valid options are str or dict.".format(type(token_param).__name__)
|
||||
error_msg = "The provided controller_oauthtoken type was not valid ({0}). Valid options are str or dict.".format(type(token_param).__name__)
|
||||
self.fail_json(msg=error_msg)
|
||||
|
||||
# Perform some basic validation
|
||||
@@ -104,14 +104,14 @@ class ControllerModule(AnsibleModule):
|
||||
try:
|
||||
self.url = urlparse(self.host)
|
||||
except Exception as e:
|
||||
self.fail_json(msg="Unable to parse tower_host as a URL ({1}): {0}".format(self.host, e))
|
||||
self.fail_json(msg="Unable to parse controller_host as a URL ({1}): {0}".format(self.host, e))
|
||||
|
||||
# Try to resolve the hostname
|
||||
hostname = self.url.netloc.split(':')[0]
|
||||
try:
|
||||
gethostbyname(hostname)
|
||||
except Exception as e:
|
||||
self.fail_json(msg="Unable to resolve tower_host ({1}): {0}".format(hostname, e))
|
||||
self.fail_json(msg="Unable to resolve controller_host ({1}): {0}".format(hostname, e))
|
||||
|
||||
def build_url(self, endpoint, query_params=None):
|
||||
# Make sure we start with /api/vX
|
||||
@@ -140,18 +140,18 @@ class ControllerModule(AnsibleModule):
|
||||
config_files.insert(2, join(local_dir, ".{0}".format(self.config_name)))
|
||||
|
||||
# If we have a specified tower config, load it
|
||||
if self.params.get('tower_config_file'):
|
||||
duplicated_params = [fn for fn in self.AUTH_ARGSPEC if fn != 'tower_config_file' and self.params.get(fn) is not None]
|
||||
if self.params.get('controller_config_file'):
|
||||
duplicated_params = [fn for fn in self.AUTH_ARGSPEC if fn != 'controller_config_file' and self.params.get(fn) is not None]
|
||||
if duplicated_params:
|
||||
self.warn(
|
||||
(
|
||||
'The parameter(s) {0} were provided at the same time as tower_config_file. '
|
||||
'The parameter(s) {0} were provided at the same time as controller_config_file. '
|
||||
'Precedence may be unstable, we suggest either using config file or params.'
|
||||
).format(', '.join(duplicated_params))
|
||||
)
|
||||
try:
|
||||
# TODO: warn if there are conflicts with other params
|
||||
self.load_config(self.params.get('tower_config_file'))
|
||||
self.load_config(self.params.get('controller_config_file'))
|
||||
except ConfigFileException as cfe:
|
||||
# Since we were told specifically to load this we want it to fail if we have an error
|
||||
self.fail_json(msg=cfe)
|
||||
|
||||
@@ -210,7 +210,7 @@ EXAMPLES = '''
|
||||
organization: test-org
|
||||
credential_type: Machine
|
||||
state: present
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
|
||||
- name: Create a valid SCM credential from a private_key file
|
||||
credential:
|
||||
@@ -244,9 +244,9 @@ EXAMPLES = '''
|
||||
name: Workshop Credential
|
||||
credential_type: MyCloudCredential
|
||||
organization: Default
|
||||
tower_username: admin
|
||||
tower_password: ansible
|
||||
tower_host: https://localhost
|
||||
controller_username: admin
|
||||
controller_password: ansible
|
||||
controller_host: https://localhost
|
||||
|
||||
- name: Create a Vaiult credential (example for notes)
|
||||
credential:
|
||||
|
||||
@@ -84,7 +84,7 @@ EXAMPLES = '''
|
||||
description: "Local Host Group"
|
||||
inventory: "Local Inventory"
|
||||
state: present
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
|
||||
- name: Add group
|
||||
group:
|
||||
|
||||
@@ -65,7 +65,7 @@ EXAMPLES = '''
|
||||
description: "Local Host Group"
|
||||
inventory: "Local Inventory"
|
||||
state: present
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
variables:
|
||||
example_var: 123
|
||||
'''
|
||||
|
||||
@@ -83,7 +83,7 @@ EXAMPLES = '''
|
||||
description: "Our Foo Cloud Servers"
|
||||
organization: "Bar Org"
|
||||
state: present
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
|
||||
- name: Copy inventory
|
||||
inventory:
|
||||
|
||||
@@ -48,7 +48,7 @@ EXAMPLES = '''
|
||||
job_list:
|
||||
status: running
|
||||
query: {"playbook": "testing.yml"}
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
register: testing_jobs
|
||||
'''
|
||||
|
||||
|
||||
@@ -315,7 +315,7 @@ EXAMPLES = '''
|
||||
credentials:
|
||||
- "Local"
|
||||
state: "present"
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
survey_enabled: yes
|
||||
survey_spec: "{{ lookup('file', 'my_survey.json') }}"
|
||||
|
||||
|
||||
@@ -226,7 +226,7 @@ EXAMPLES = '''
|
||||
error:
|
||||
message: "{{ '{{ job_friendly_name }} FAILED! Please look at {{ job.url }}' }}"
|
||||
state: present
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
|
||||
- name: Add webhook notification
|
||||
notification_template:
|
||||
@@ -237,7 +237,7 @@ EXAMPLES = '''
|
||||
headers:
|
||||
X-Custom-Header: value123
|
||||
state: present
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
|
||||
- name: Add email notification
|
||||
notification_template:
|
||||
@@ -254,7 +254,7 @@ EXAMPLES = '''
|
||||
use_tls: no
|
||||
use_ssl: no
|
||||
state: present
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
|
||||
- name: Add twilio notification
|
||||
notification_template:
|
||||
@@ -267,7 +267,7 @@ EXAMPLES = '''
|
||||
to_numbers:
|
||||
- '+15553334444'
|
||||
state: present
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
|
||||
- name: Add PagerDuty notification
|
||||
notification_template:
|
||||
@@ -279,7 +279,7 @@ EXAMPLES = '''
|
||||
client_name: client
|
||||
service_key: a_key
|
||||
state: present
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
|
||||
- name: Add IRC notification
|
||||
notification_template:
|
||||
@@ -294,13 +294,13 @@ EXAMPLES = '''
|
||||
server: irc.example.com
|
||||
use_ssl: no
|
||||
state: present
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
|
||||
- name: Delete notification
|
||||
notification_template:
|
||||
name: old notification
|
||||
state: absent
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
|
||||
- name: Copy webhook notification
|
||||
notification_template:
|
||||
|
||||
@@ -91,14 +91,14 @@ EXAMPLES = '''
|
||||
name: "Foo"
|
||||
description: "Foo bar organization"
|
||||
state: present
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
|
||||
- name: Create organization using 'foo-venv' as default Python virtualenv
|
||||
organization:
|
||||
name: "Foo"
|
||||
description: "Foo bar organization using foo-venv"
|
||||
state: present
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
|
||||
- name: Create organization that pulls content from galaxy.ansible.com
|
||||
organization:
|
||||
@@ -106,7 +106,7 @@ EXAMPLES = '''
|
||||
state: present
|
||||
galaxy_credentials:
|
||||
- Ansible Galaxy
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
'''
|
||||
|
||||
from ..module_utils.controller_api import ControllerAPIModule
|
||||
|
||||
@@ -176,7 +176,7 @@ EXAMPLES = '''
|
||||
description: "Foo bar project"
|
||||
organization: "test"
|
||||
state: present
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
|
||||
- name: Add Project with cache timeout
|
||||
project:
|
||||
@@ -186,7 +186,7 @@ EXAMPLES = '''
|
||||
scm_update_on_launch: True
|
||||
scm_update_cache_timeout: 60
|
||||
state: present
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
|
||||
- name: Copy project
|
||||
project:
|
||||
|
||||
@@ -104,7 +104,7 @@ EXAMPLES = '''
|
||||
- name: Export all Automation Platform Controller assets
|
||||
receive:
|
||||
all: True
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
|
||||
- name: Export all inventories
|
||||
receive:
|
||||
|
||||
@@ -65,7 +65,7 @@ EXAMPLES = '''
|
||||
- name: Import all Automation Platform Controller assets
|
||||
send:
|
||||
assets: "{{ export_output.assets }}"
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
|
||||
@@ -56,7 +56,7 @@ EXAMPLES = '''
|
||||
description: Team Description
|
||||
organization: test-org
|
||||
state: present
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
'''
|
||||
|
||||
from ..module_utils.controller_api import ControllerAPIModule
|
||||
|
||||
@@ -22,7 +22,7 @@ description:
|
||||
- Create or destroy Automation Platform Controller tokens. See
|
||||
U(https://www.ansible.com/tower) for an overview.
|
||||
- In addition, the module sets an Ansible fact which can be passed into other
|
||||
controller modules as the parameter tower_oauthtoken. See examples for usage.
|
||||
controller modules as the parameter controller_oauthtoken. See examples for usage.
|
||||
- Because of the sensitive nature of tokens, the created token value is only available once
|
||||
through the Ansible fact. (See RETURN for details)
|
||||
- Due to the nature of tokens this module is not idempotent. A second will
|
||||
@@ -49,7 +49,7 @@ options:
|
||||
default: 'write'
|
||||
choices: ["read", "write"]
|
||||
existing_token:
|
||||
description: The data structure produced from tower_token in create mode to be used with state absent.
|
||||
description: The data structure produced from token in create mode to be used with state absent.
|
||||
type: dict
|
||||
existing_token_id:
|
||||
description: A token ID (number) which can be used to delete an arbitrary token with state absent.
|
||||
@@ -70,11 +70,11 @@ EXAMPLES = '''
|
||||
description: '{{ token_description }}'
|
||||
scope: "write"
|
||||
state: present
|
||||
tower_oauthtoken: "{{ my_existing_token }}"
|
||||
controller_oauthtoken: "{{ my_existing_token }}"
|
||||
|
||||
- name: Delete this token
|
||||
token:
|
||||
existing_token: "{{ tower_token }}"
|
||||
existing_token: "{{ token }}"
|
||||
state: absent
|
||||
|
||||
- name: Create a new token using username/password
|
||||
@@ -82,19 +82,19 @@ EXAMPLES = '''
|
||||
description: '{{ token_description }}'
|
||||
scope: "write"
|
||||
state: present
|
||||
tower_username: "{{ my_username }}"
|
||||
tower_password: "{{ my_password }}"
|
||||
controller_username: "{{ my_username }}"
|
||||
controller_password: "{{ my_password }}"
|
||||
|
||||
- name: Use our new token to make another call
|
||||
job_list:
|
||||
tower_oauthtoken: "{{ tower_token }}"
|
||||
controller_oauthtoken: "{{ token }}"
|
||||
|
||||
always:
|
||||
- name: Delete our Token with the token we created
|
||||
token:
|
||||
existing_token: "{{ tower_token }}"
|
||||
existing_token: "{{ token }}"
|
||||
state: absent
|
||||
when: tower_token is defined
|
||||
when: token is defined
|
||||
|
||||
- name: Delete a token by its id
|
||||
token:
|
||||
@@ -125,7 +125,7 @@ def return_token(module, last_response):
|
||||
# This method will return the entire token object we got back so that a user has access to the token
|
||||
|
||||
module.json_output['ansible_facts'] = {
|
||||
'tower_token': last_response,
|
||||
'token': last_response,
|
||||
}
|
||||
module.exit_json(**module.json_output)
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ EXAMPLES = '''
|
||||
first_name: John
|
||||
last_name: Doe
|
||||
state: present
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
|
||||
- name: Add user as a system administrator
|
||||
user:
|
||||
@@ -88,7 +88,7 @@ EXAMPLES = '''
|
||||
email: jdoe@example.org
|
||||
superuser: yes
|
||||
state: present
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
|
||||
- name: Add user as a system auditor
|
||||
user:
|
||||
@@ -97,14 +97,14 @@ EXAMPLES = '''
|
||||
email: jdoe@example.org
|
||||
auditor: yes
|
||||
state: present
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
|
||||
- name: Delete user
|
||||
user:
|
||||
username: jdoe
|
||||
email: jdoe@example.org
|
||||
state: absent
|
||||
tower_config_file: "~/tower_cli.cfg"
|
||||
controller_config_file: "~/tower_cli.cfg"
|
||||
'''
|
||||
|
||||
from ..module_utils.controller_api import ControllerAPIModule
|
||||
|
||||
Reference in New Issue
Block a user