Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameter 'cloud_type' to azure_keyvault_secret.py #1517

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions plugins/lookup/azure_keyvault_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
description: Tenant id of service principal.
use_msi:
description: MSI token autodiscover, default is true.
cloud_type:
description: Specify which cloud, such as C(azure), C(usgovcloudapi).
notes:
- If version is not provided, this plugin will return the latest version of the secret.
- If ansible is running on Azure Virtual Machine with MSI enabled, client_id, secret and tenant isn't required.
Expand All @@ -51,6 +53,10 @@
debug:
msg: msg: "{{ lookup('azure.azcollection.azure_keyvault_secret', 'testsecret', vault_url=key_vault_uri)}}"

- name: Look up secret with cloud type
debug:
msg: msg: "{{ lookup('azure.azcollection.azure_keyvault_secret', 'testsecret', cloud_type='usgovcloudapi', vault_url=key_vault_uri)}}"

- name: Look up secret when ansible host is MSI enabled Azure VM
debug:
msg: "the value of this secret is {{
Expand Down Expand Up @@ -133,15 +139,6 @@

logger = logging.getLogger("azure.identity").setLevel(logging.ERROR)

token_params = {
'api-version': '2018-02-01',
'resource': 'https://vault.azure.net'
}

token_headers = {
'Metadata': 'true'
}


def lookup_secret_non_msi(terms, vault_url, kwargs):

Expand Down Expand Up @@ -178,6 +175,15 @@ def run(self, terms, variables, **kwargs):
TOKEN_ACQUIRED = False
token = None

token_params = {
'api-version': '2018-02-01',
'resource': 'https://vault.{0}.net'.format(kwargs.get('cloud_type', 'azure'))
}

token_headers = {
'Metadata': 'true'
}

if use_msi:
try:
token_res = requests.get('http://169.254.169.254/metadata/identity/oauth2/token',
Expand Down