【问题标题】:azure_rm_resourcegroup does work in azure cloud shell but not locallyqazure_rm_resourcegroup 在 azure cloud shell 中工作,但在本地不工作
【发布时间】:2019-03-20 13:49:01
【问题描述】:

我可以在 azure cloud shell 中使用以下 ansible playbook 创建资源组,但不能从我的本地 PC 中创建。为什么?我尝试多次重新创建应用程序/秘密,但没有任何效果。

- name: Create Azure Kubernetes Service
  hosts: localhost
  connection: local
  vars:
    resource_group: birdy71
    location: westeurope
    aks_name: birdy7-cluster
    username: birdy7
    ssh_key: "ssh-rsa xxxxxxxx"
    client_id: "xxxx"
    client_secret: "xxx"
    tenant: "xxx"
    subscription_id: "xxx"
  tasks:
  - name: Create resource group
    azure_rm_resourcegroup:
      name: "{{ resource_group }}"
      location: "{{ location }}"
      client_id: "{{ client_id }}"
      secret: "{{ client_secret }}"
      subscription_id: "{{ subscription_id }}"
      tenant: "{{ tenant }}"

在 azure cloud shell 中,我完全删除了 ~/.azure 文件夹,但它仍然可以工作。在我的本地电脑上,我收到此错误:AADSTS7000215: Invalid client secret is provided。

但这怎么可能呢?如果在 azure cloud shell 中使用该秘密,则效果很好。

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: Timestamp: 2019-03-20 13: 34: 02Z
fatal: [localhost
]: FAILED! => {
  "changed": false,
  "module_stderr": "Traceback (most recent call last):\n  File \"/Users/tobias/.ansible/tmp/ansible-tmp-1553088840.81-75656009010434/AnsiballZ_azure_rm_resourcegroup.py\", line 113, in <module>\n    _ansiballz_main()\n  File \"/Users/tobias/.ansible/tmp/ansible-tmp-1553088840.81-75656009010434/AnsiballZ_azure_rm_resourcegroup.py\", line 105, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/Users/tobias/.ansible/tmp/ansible-tmp-1553088840.81-75656009010434/AnsiballZ_azure_rm_resourcegroup.py\", line 48, in invoke_module\n    imp.load_module('__main__', mod, module, MOD_DESC)\n  File \"/var/folders/fl/pps_zz4s3lx6569226xr_2bh0000gn/T/ansible_azure_rm_resourcegroup_payload_CeouHT/__main__.py\", line 256, in <module>\n  File \"/var/folders/fl/pps_zz4s3lx6569226xr_2bh0000gn/T/ansible_azure_rm_resourcegroup_payload_CeouHT/__main__.py\", line 252, in main\n  File \"/var/folders/fl/pps_zz4s3lx6569226xr_2bh0000gn/T/ansible_azure_rm_resourcegroup_payload_CeouHT/__main__.py\", line 136, in __init__\n  File \"/var/folders/fl/pps_zz4s3lx6569226xr_2bh0000gn/T/ansible_azure_rm_resourcegroup_payload_CeouHT/ansible_azure_rm_resourcegroup_payload.zip/ansible/module_utils/azure_rm_common.py\", line 301, in __init__\n  File \"/var/folders/fl/pps_zz4s3lx6569226xr_2bh0000gn/T/ansible_azure_rm_resourcegroup_payload_CeouHT/ansible_azure_rm_resourcegroup_payload.zip/ansible/module_utils/azure_rm_common.py\", line 1021, in __init__\n  File \"/Users/tobias/.venv/azure2/lib/python2.7/site-packages/msrestazure/azure_active_directory.py\", line 453, in __init__\n    self.set_token()\n  File \"/Users/tobias/.venv/azure2/lib/python2.7/site-packages/msrestazure/azure_active_directory.py\", line 480, in set_token\n    raise_with_traceback(AuthenticationError, \"\", err)\n  File \"/Users/tobias/.venv/azure2/lib/python2.7/site-packages/msrest/exceptions.py\", line 48, in raise_with_traceback\n    raise error\nmsrest.exceptions.AuthenticationError: , InvalidClientError: (invalid_client) AADSTS7000215: Invalid client secret is provided.\r\nTrace ID: c7fab593-93e7-415f-a3e8-5ba973e81e00\r\nCorrelation ID: 5ee1181d-f0ac-4c08-a0e7-dfba9c722073\r\nTimestamp: 2019-03-20 13:34:02Z\n",
  "module_stdout": "",
  "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
  "rc": 1
}

【问题讨论】:

  • 您需要事先使用 az cli 对 azure 进行身份验证,您这样做了吗?或以其他方式提供凭据
  • 还有问题吗?或者如果它有帮助,你可以接受它。

标签: azure ansible azure-aks


【解决方案1】:

我可以重现发生在你身上的错误:

从错误中可以看出你遇到的核心问题:

InvalidClientError: (invalid_client) AADSTS7000215: 无效客户端 提供了秘密。

所以你必须输入错误的服务主体密码。对于服务主体秘密,您可以在创建时看到它。所以我建议你如果真的不记得可以通过CLI命令az ad sp credential reset重置密码。

另外,您可以通过 CLI 命令检查您的服务主体的密码是否正确:

az login --service-principal --username APP_ID --password PASSWORD --tenant TENANT_ID

另外,当你使用 Cloud Shell 执行 ansible 时,意思是 Azure 的 Automatic credential。见Automatic credential configuration

登录到 Cloud Shell 后,Ansible 向 Azure 进行身份验证以 无需任何额外配置即可管理基础架构。

下面的截图是我测试的结果:

【讨论】:

    【解决方案2】:

    解决方案是重新生成我的客户端密码,直到我得到一个没有特殊字符(如“&”和“\”)的密码。 :-(

    【讨论】:

    • 你确定吗?我的秘密还包含字符“@”并且有效。
    猜你喜欢
    • 1970-01-01
    • 2016-09-21
    • 1970-01-01
    • 1970-01-01
    • 2021-06-03
    • 1970-01-01
    • 2019-01-18
    • 2021-08-05
    • 2016-06-20
    相关资源
    最近更新 更多