【问题标题】:Ansible Lookup with azure_keyvault_secret Invalid Credentails使用 azure_keyvault_secret 无效的 Credentails 进行 Ansible 查找
【发布时间】:2020-01-30 19:55:16
【问题描述】:

我正在尝试使用 Ansible 检索存储在 Azure Key Vault 中的机密。我使用 ansible-galaxy 找到并安装了azure.azure_preview_modules。我还更新了 ansible.cfg 以从角色指向 lookup_plugins 目录。运行以下剧本时出现错误:


- hosts: localhost
  connection: local
  roles:
    - { role: azure.azure_preview_modules }
  tasks:
    - name: Look up secret when ansible host is general VM
      vars:
        url: 'https://myVault.vault.azure.net/'
        secretname: 'SecretPassword'
        client_id: 'ServicePrincipalIDHere'
        secret: 'ServicePrinipcalPassHere'
        tenant: 'TenantIDHere'
      debug: msg="the value of this secret is {{lookup('azure_keyvault_secret',secretname,vault_url=url, cliend_id=client_id, secret=secret, tenant_id=tenant)}}"


fatal: [localhost]: FAILED! => {"msg": "An unhandled exception occurred while running the lookup plugin 'azure_keyvault_secret'. Error was a <class 'ansible.errors.AnsibleError'>, original message: Invalid credentials provided."}

使用相同的信息,我可以使用 AZ PowerShell 和 AZCLI 连接到 Azure,并在命令行中检索 Azure Key Vault 机密。但是,对于使用查找插件的 playbook,这些相同的凭据在此任务中不起作用。

【问题讨论】:

    标签: azure ansible azure-keyvault


    【解决方案1】:

    我在使用 python sdk(ansible 建立在其之上)时遇到了类似的错误。尝试将网址更改为:

    url: 'https://myVault.vault.azure.net' # so remove the trailing slash
    

    错误文本 101% 具有误导性

    【讨论】:

      【解决方案2】:

      经过一番努力,我找到了问题所在!示例中的参数 client_id 拼写错误,我没有抓住它导致错误。 client_id=client_id,

      https://github.com/Azure/azure_preview_modules/blob/master/lookup_plugins/azure_keyvault_secret.py#L49

      下面的更正示例。

      - name: Look up secret when ansible host is general VM
        vars:
          url: 'https://valueName.vault.azure.net'
          secretname: 'secretName/version'
          client_id: 'ServicePrincipalID'
          secret: 'P@ssw0rd'
          tenant: 'tenantID'
        debug: msg="the value of this secret is {{lookup('azure_keyvault_secret',secretname,vault_url=url, client_id=client_id, secret=secret, tenant_id=tenant)}}"
      

      【讨论】:

        猜你喜欢
        • 2018-06-26
        • 1970-01-01
        • 2018-07-11
        • 2020-06-02
        • 1970-01-01
        • 1970-01-01
        • 2017-03-01
        • 2011-05-21
        • 1970-01-01
        相关资源
        最近更新 更多