From b90a296d4196ccccf99a1ba9bfb00ee9de796edb Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Tue, 7 Apr 2020 10:00:02 -0400 Subject: [PATCH] Document and align the env var for OAuth token --- awx_collection/plugins/doc_fragments/auth.py | 5 +++++ awx_collection/plugins/module_utils/ansible_tower.py | 2 +- awx_collection/plugins/module_utils/tower_api.py | 2 +- awx_collection/plugins/modules/tower_credential.py | 1 + awx_collection/plugins/modules/tower_credential_type.py | 1 + awx_collection/plugins/modules/tower_group.py | 1 + awx_collection/plugins/modules/tower_host.py | 1 + awx_collection/plugins/modules/tower_inventory.py | 1 + awx_collection/plugins/modules/tower_inventory_source.py | 1 + awx_collection/plugins/modules/tower_job_cancel.py | 1 + awx_collection/plugins/modules/tower_job_launch.py | 1 + awx_collection/plugins/modules/tower_job_list.py | 1 + awx_collection/plugins/modules/tower_job_template.py | 1 + awx_collection/plugins/modules/tower_job_wait.py | 1 + awx_collection/plugins/modules/tower_label.py | 1 + awx_collection/plugins/modules/tower_license.py | 1 + awx_collection/plugins/modules/tower_notification.py | 1 + awx_collection/plugins/modules/tower_organization.py | 1 + awx_collection/plugins/modules/tower_project.py | 1 + awx_collection/plugins/modules/tower_role.py | 1 + awx_collection/plugins/modules/tower_settings.py | 1 + awx_collection/plugins/modules/tower_team.py | 1 + awx_collection/plugins/modules/tower_user.py | 1 + .../plugins/modules/tower_workflow_job_template.py | 1 + .../plugins/modules/tower_workflow_job_template_node.py | 1 + awxkit/awxkit/cli/docs/source/authentication.rst | 2 +- awxkit/awxkit/cli/docs/source/usage.rst | 2 +- awxkit/awxkit/cli/format.py | 2 +- awxkit/awxkit/cli/resource.py | 2 +- 29 files changed, 33 insertions(+), 6 deletions(-) diff --git a/awx_collection/plugins/doc_fragments/auth.py b/awx_collection/plugins/doc_fragments/auth.py index bc02d5f420..ab6eded044 100644 --- a/awx_collection/plugins/doc_fragments/auth.py +++ b/awx_collection/plugins/doc_fragments/auth.py @@ -15,20 +15,25 @@ options: tower_host: description: - URL to your Tower or AWX instance. + - If value not set, will try environment variable C(TOWER_HOST) and then config files + default: '127.0.0.1' type: str tower_username: description: - Username for your Tower or AWX instance. + - If value not set, will try environment variable C(TOWER_USERNAME) and then config files type: str tower_password: description: - Password for your Tower or AWX instance. + - If value not set, will try environment variable C(TOWER_PASSWORD) and then config files type: str validate_certs: description: - Whether to allow insecure connections to Tower or 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 type: bool aliases: [ tower_verify_ssl ] tower_config_file: diff --git a/awx_collection/plugins/module_utils/ansible_tower.py b/awx_collection/plugins/module_utils/ansible_tower.py index c51b410127..1610183c9a 100644 --- a/awx_collection/plugins/module_utils/ansible_tower.py +++ b/awx_collection/plugins/module_utils/ansible_tower.py @@ -124,7 +124,7 @@ def tower_check_mode(module): class TowerModule(AnsibleModule): def __init__(self, argument_spec, **kwargs): args = dict( - tower_host=dict(), + tower_host=dict(default='127.0.0.1'), tower_username=dict(), tower_password=dict(no_log=True), validate_certs=dict(type='bool', aliases=['tower_verify_ssl']), diff --git a/awx_collection/plugins/module_utils/tower_api.py b/awx_collection/plugins/module_utils/tower_api.py index b7145e15f4..4fc32d8e6b 100644 --- a/awx_collection/plugins/module_utils/tower_api.py +++ b/awx_collection/plugins/module_utils/tower_api.py @@ -47,7 +47,7 @@ class TowerModule(AnsibleModule): def __init__(self, argument_spec, **kwargs): args = dict( - tower_host=dict(required=False, fallback=(env_fallback, ['TOWER_HOST'])), + tower_host=dict(required=False, default='127.0.0.1', fallback=(env_fallback, ['TOWER_HOST'])), tower_username=dict(required=False, fallback=(env_fallback, ['TOWER_USERNAME'])), tower_password=dict(no_log=True, required=False, fallback=(env_fallback, ['TOWER_PASSWORD'])), validate_certs=dict(type='bool', aliases=['tower_verify_ssl'], required=False, fallback=(env_fallback, ['TOWER_VERIFY_SSL'])), diff --git a/awx_collection/plugins/modules/tower_credential.py b/awx_collection/plugins/modules/tower_credential.py index b91d020cda..3f01283c0d 100644 --- a/awx_collection/plugins/modules/tower_credential.py +++ b/awx_collection/plugins/modules/tower_credential.py @@ -187,6 +187,7 @@ options: tower_oauthtoken: description: - The Tower OAuth token to use. + - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files required: False type: str version_added: "3.7" diff --git a/awx_collection/plugins/modules/tower_credential_type.py b/awx_collection/plugins/modules/tower_credential_type.py index 5f1a3f5057..2c9217a1e3 100644 --- a/awx_collection/plugins/modules/tower_credential_type.py +++ b/awx_collection/plugins/modules/tower_credential_type.py @@ -62,6 +62,7 @@ options: tower_oauthtoken: description: - The Tower OAuth token to use. + - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files type: str version_added: "3.7" extends_documentation_fragment: awx.awx.auth diff --git a/awx_collection/plugins/modules/tower_group.py b/awx_collection/plugins/modules/tower_group.py index 8bec2ae989..91504d4d9b 100644 --- a/awx_collection/plugins/modules/tower_group.py +++ b/awx_collection/plugins/modules/tower_group.py @@ -67,6 +67,7 @@ options: tower_oauthtoken: description: - The Tower OAuth token to use. + - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files type: str version_added: "3.7" extends_documentation_fragment: awx.awx.auth diff --git a/awx_collection/plugins/modules/tower_host.py b/awx_collection/plugins/modules/tower_host.py index 16962ccc60..9d2698e4e5 100644 --- a/awx_collection/plugins/modules/tower_host.py +++ b/awx_collection/plugins/modules/tower_host.py @@ -60,6 +60,7 @@ options: tower_oauthtoken: description: - The Tower OAuth token to use. + - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files type: str version_added: "3.7" extends_documentation_fragment: awx.awx.auth diff --git a/awx_collection/plugins/modules/tower_inventory.py b/awx_collection/plugins/modules/tower_inventory.py index e3981ea68b..d17d202c98 100644 --- a/awx_collection/plugins/modules/tower_inventory.py +++ b/awx_collection/plugins/modules/tower_inventory.py @@ -62,6 +62,7 @@ options: tower_oauthtoken: description: - The Tower OAuth token to use. + - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files type: str version_added: "3.7" extends_documentation_fragment: awx.awx.auth diff --git a/awx_collection/plugins/modules/tower_inventory_source.py b/awx_collection/plugins/modules/tower_inventory_source.py index a2e65d2ee6..0bd848bbec 100644 --- a/awx_collection/plugins/modules/tower_inventory_source.py +++ b/awx_collection/plugins/modules/tower_inventory_source.py @@ -122,6 +122,7 @@ options: tower_oauthtoken: description: - The Tower OAuth token to use. + - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files type: str version_added: "3.7" extends_documentation_fragment: awx.awx.auth diff --git a/awx_collection/plugins/modules/tower_job_cancel.py b/awx_collection/plugins/modules/tower_job_cancel.py index f3a852df25..b92a3134a1 100644 --- a/awx_collection/plugins/modules/tower_job_cancel.py +++ b/awx_collection/plugins/modules/tower_job_cancel.py @@ -36,6 +36,7 @@ options: tower_oauthtoken: description: - The Tower OAuth token to use. + - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files type: str version_added: "3.7" extends_documentation_fragment: awx.awx.auth diff --git a/awx_collection/plugins/modules/tower_job_launch.py b/awx_collection/plugins/modules/tower_job_launch.py index a9e61eee58..6eec83b163 100644 --- a/awx_collection/plugins/modules/tower_job_launch.py +++ b/awx_collection/plugins/modules/tower_job_launch.py @@ -90,6 +90,7 @@ options: tower_oauthtoken: description: - The Tower OAuth token to use. + - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files type: str version_added: "3.7" extends_documentation_fragment: awx.awx.auth diff --git a/awx_collection/plugins/modules/tower_job_list.py b/awx_collection/plugins/modules/tower_job_list.py index f628ccc99c..ad105ed631 100644 --- a/awx_collection/plugins/modules/tower_job_list.py +++ b/awx_collection/plugins/modules/tower_job_list.py @@ -44,6 +44,7 @@ options: tower_oauthtoken: description: - The Tower OAuth token to use. + - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files type: str version_added: "3.7" extends_documentation_fragment: awx.awx.auth diff --git a/awx_collection/plugins/modules/tower_job_template.py b/awx_collection/plugins/modules/tower_job_template.py index da6ba91dbc..6266c80082 100644 --- a/awx_collection/plugins/modules/tower_job_template.py +++ b/awx_collection/plugins/modules/tower_job_template.py @@ -272,6 +272,7 @@ options: tower_oauthtoken: description: - The Tower OAuth token to use. + - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files type: str version_added: "3.7" diff --git a/awx_collection/plugins/modules/tower_job_wait.py b/awx_collection/plugins/modules/tower_job_wait.py index 7e2eaa3cc0..84a24bc77c 100644 --- a/awx_collection/plugins/modules/tower_job_wait.py +++ b/awx_collection/plugins/modules/tower_job_wait.py @@ -52,6 +52,7 @@ options: tower_oauthtoken: description: - The Tower OAuth token to use. + - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files required: False type: str version_added: "3.7" diff --git a/awx_collection/plugins/modules/tower_label.py b/awx_collection/plugins/modules/tower_label.py index 96edf1a7f1..f1496b053e 100644 --- a/awx_collection/plugins/modules/tower_label.py +++ b/awx_collection/plugins/modules/tower_label.py @@ -48,6 +48,7 @@ options: tower_oauthtoken: description: - The Tower OAuth token to use. + - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files type: str version_added: "3.7" extends_documentation_fragment: awx.awx.auth diff --git a/awx_collection/plugins/modules/tower_license.py b/awx_collection/plugins/modules/tower_license.py index 14c3c0a779..1d8fdefa3a 100644 --- a/awx_collection/plugins/modules/tower_license.py +++ b/awx_collection/plugins/modules/tower_license.py @@ -37,6 +37,7 @@ options: tower_oauthtoken: description: - The Tower OAuth token to use. + - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files type: str version_added: "3.7" extends_documentation_fragment: awx.awx.auth diff --git a/awx_collection/plugins/modules/tower_notification.py b/awx_collection/plugins/modules/tower_notification.py index 613d38b716..bae4302449 100644 --- a/awx_collection/plugins/modules/tower_notification.py +++ b/awx_collection/plugins/modules/tower_notification.py @@ -213,6 +213,7 @@ options: tower_oauthtoken: description: - The Tower OAuth token to use. + - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files version_added: "3.7" type: str extends_documentation_fragment: awx.awx.auth diff --git a/awx_collection/plugins/modules/tower_organization.py b/awx_collection/plugins/modules/tower_organization.py index bb28c9ef25..2b1de03f73 100644 --- a/awx_collection/plugins/modules/tower_organization.py +++ b/awx_collection/plugins/modules/tower_organization.py @@ -53,6 +53,7 @@ options: tower_oauthtoken: description: - The Tower OAuth token to use. + - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files type: str version_added: "3.7" extends_documentation_fragment: awx.awx.auth diff --git a/awx_collection/plugins/modules/tower_project.py b/awx_collection/plugins/modules/tower_project.py index b9176601e5..d01b371474 100644 --- a/awx_collection/plugins/modules/tower_project.py +++ b/awx_collection/plugins/modules/tower_project.py @@ -122,6 +122,7 @@ options: tower_oauthtoken: description: - The Tower OAuth token to use. + - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files type: str version_added: "3.7" extends_documentation_fragment: awx.awx.auth diff --git a/awx_collection/plugins/modules/tower_role.py b/awx_collection/plugins/modules/tower_role.py index 698623bf60..fc0266fb8e 100644 --- a/awx_collection/plugins/modules/tower_role.py +++ b/awx_collection/plugins/modules/tower_role.py @@ -79,6 +79,7 @@ options: tower_oauthtoken: description: - The Tower OAuth token to use. + - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files type: str version_added: "3.7" diff --git a/awx_collection/plugins/modules/tower_settings.py b/awx_collection/plugins/modules/tower_settings.py index 034d898026..6963d23beb 100644 --- a/awx_collection/plugins/modules/tower_settings.py +++ b/awx_collection/plugins/modules/tower_settings.py @@ -41,6 +41,7 @@ options: tower_oauthtoken: description: - The Tower OAuth token to use. + - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files type: str version_added: "3.7" requirements: diff --git a/awx_collection/plugins/modules/tower_team.py b/awx_collection/plugins/modules/tower_team.py index 2c03d88b7c..c581bebf4d 100644 --- a/awx_collection/plugins/modules/tower_team.py +++ b/awx_collection/plugins/modules/tower_team.py @@ -51,6 +51,7 @@ options: tower_oauthtoken: description: - The Tower OAuth token to use. + - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files type: str version_added: "3.7" extends_documentation_fragment: awx.awx.auth diff --git a/awx_collection/plugins/modules/tower_user.py b/awx_collection/plugins/modules/tower_user.py index 92954d7824..eac8d70bed 100644 --- a/awx_collection/plugins/modules/tower_user.py +++ b/awx_collection/plugins/modules/tower_user.py @@ -65,6 +65,7 @@ options: tower_oauthtoken: description: - The Tower OAuth token to use. + - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files type: str version_added: "3.7" extends_documentation_fragment: awx.awx.auth diff --git a/awx_collection/plugins/modules/tower_workflow_job_template.py b/awx_collection/plugins/modules/tower_workflow_job_template.py index 1c9ec00f74..c22086a939 100644 --- a/awx_collection/plugins/modules/tower_workflow_job_template.py +++ b/awx_collection/plugins/modules/tower_workflow_job_template.py @@ -110,6 +110,7 @@ options: tower_oauthtoken: description: - The Tower OAuth token to use. + - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files type: str version_added: "3.7" extends_documentation_fragment: awx.awx.auth diff --git a/awx_collection/plugins/modules/tower_workflow_job_template_node.py b/awx_collection/plugins/modules/tower_workflow_job_template_node.py index 500595c451..8e271014d1 100644 --- a/awx_collection/plugins/modules/tower_workflow_job_template_node.py +++ b/awx_collection/plugins/modules/tower_workflow_job_template_node.py @@ -138,6 +138,7 @@ options: tower_oauthtoken: description: - The Tower OAuth token to use. + - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files type: str version_added: "3.7" extends_documentation_fragment: awx.awx.auth diff --git a/awxkit/awxkit/cli/docs/source/authentication.rst b/awxkit/awxkit/cli/docs/source/authentication.rst index b6dc33d4c3..774366e0be 100644 --- a/awxkit/awxkit/cli/docs/source/authentication.rst +++ b/awxkit/awxkit/cli/docs/source/authentication.rst @@ -22,7 +22,7 @@ value: .. code:: bash - export TOWER_TOKEN=6E5SXhld7AMOhpRveZsLJQsfs9VS8U + export TOWER_OAUTH_TOKEN=6E5SXhld7AMOhpRveZsLJQsfs9VS8U By ingesting this token, you can run subsequent CLI commands without having to specify your username and password each time: diff --git a/awxkit/awxkit/cli/docs/source/usage.rst b/awxkit/awxkit/cli/docs/source/usage.rst index 0633bb9840..b22e3c7dbb 100644 --- a/awxkit/awxkit/cli/docs/source/usage.rst +++ b/awxkit/awxkit/cli/docs/source/usage.rst @@ -89,5 +89,5 @@ A few of the most important ones are: ``--conf.password, TOWER_PASSWORD`` the AWX password to use for authentication -``--conf.token, TOWER_TOKEN`` +``--conf.token, TOWER_OAUTH_TOKEN`` an OAuth2.0 token to use for authentication diff --git a/awxkit/awxkit/cli/format.py b/awxkit/awxkit/cli/format.py index ca91a822f4..34b1cd5b29 100644 --- a/awxkit/awxkit/cli/format.py +++ b/awxkit/awxkit/cli/format.py @@ -16,7 +16,7 @@ def add_authentication_arguments(parser, env): ) auth.add_argument( '--conf.token', - default=env.get('TOWER_TOKEN', ''), + default=env.get('TOWER_OAUTH_TOKEN', env.get('TOWER_TOKEN', '')), help='an OAuth2.0 token (get one by using `awx login`)', metavar='TEXT', ) diff --git a/awxkit/awxkit/cli/resource.py b/awxkit/awxkit/cli/resource.py index a162c36fc8..c70aa5050d 100644 --- a/awxkit/awxkit/cli/resource.py +++ b/awxkit/awxkit/cli/resource.py @@ -102,7 +102,7 @@ class Login(CustomCommand): else: fmt = client.get_config('format') if fmt == 'human': - print('export TOWER_TOKEN={}'.format(token)) + print('export TOWER_OAUTH_TOKEN={}'.format(token)) else: print(to_str(FORMATTERS[fmt]({'token': token}, '.')).strip())