Ansible塔式凭证类型未设置环境变量

问题描述

上下文:

  1. 我正在运行Ansible AWX / Tower,并将其作为项目源连接到Git存储库。
  2. 我使用插件(azure_rm)定义了动态广告资源。
  3. 我已经在Azure AD中创建了具有正确访问权限的服务原则(已确认)。
  4. 我正在Ansible塔中使用该服务主体来通过azure_rm插件运行动态清单。但是每次都会失败。

代码

  1. 我创建了一个用于设置环境变量的自定义凭据。在文档here
  2. 中,应根据服务主体的要求定义了应该设置的环境变量。
# Input configuration
fields:
  - id: client_id
    type: string
    label: Client ID
  - id: client_secret
    type: string
    label: Client Secret
    secret: true
  - id: tenant_id
    type: string
    label: Tenant ID
  - id: subscription_id
    type: string
    label: Subscription ID
required:
  - client_id
  - client_secret
  - tenant_id
# Output Configuration
env:
  AZURE_CLIENT_ID: '{{ client_id }}'
  AZURE_SECRET: '{{ client_secret }}'
  AZURE_SUBSCRIPTION_ID: '{{ subscription_id }}'
  AZURE_TENANT: '{{ tenant_id }}'
  1. 以上凭证类型用于创建凭证,并在库存源中使用。
  2. 库存来源如下:
plugin: azure_rm

batch_fetch: yes
cert_validation_mode: ignore

group_by_os_family: yes

include_vm_resource_groups:
- exampleRG

  1. 这是我每次都遇到的错误
[WARNING]:  * Failed to parse
/tmp/awx_64_77si0uqt/project/inventories/development/hosts.yml with auto
plugin: inventory config
'/tmp/awx_64_77si0uqt/project/inventories/development/hosts.yml' Could not be
verified by plugin 'azure_rm'
  File "/usr/lib/python2.7/site-packages/ansible/inventory/manager.py",line 280,in parse_source
    plugin.parse(self._inventory,self._loader,source,cache=cache)
  File "/usr/lib/python2.7/site-packages/ansible/plugins/inventory/auto.py",line 56,in parse
    raise AnsibleParserError("inventory config '{0}' Could not be verified by plugin '{1}'".format(path,plugin_name))
[WARNING]:  * Failed to parse
/tmp/awx_64_77si0uqt/project/inventories/development/hosts.yml with yaml
plugin: Plugin configuration YAML file,not YAML inventory
  File "/usr/lib/python2.7/site-packages/ansible/inventory/manager.py",cache=cache)
  File "/usr/lib/python2.7/site-packages/ansible/plugins/inventory/yaml.py",line 112,in parse
    raise AnsibleParserError('Plugin configuration YAML file,not YAML inventory')
[WARNING]:  * Failed to parse
/tmp/awx_64_77si0uqt/project/inventories/development/hosts.yml with ini plugin:
Invalid host pattern 'plugin:' supplied,ending in ':' is not allowed,this
character is reserved to provide a port.
  File "/usr/lib/python2.7/site-packages/ansible/inventory/manager.py",cache=cache)
  File "/usr/lib/python2.7/site-packages/ansible/plugins/inventory/ini.py",line 138,in parse
    raise AnsibleParserError(e)
[WARNING]: Unable to parse
/tmp/awx_64_77si0uqt/project/inventories/development/hosts.yml as an inventory
source
[WARNING]: Unable to parse /tmp/awx_64_77si0uqt/project/inventories/development
as an inventory source
ERROR! No inventory was parsed,please check your configuration and options.

此外,这在手动设置环境变量后在本地ansible cli中运行时也有效。因此,明显的怀疑是AWX并未按预期设置环境变量,并且错误日志并不是超级有用。

这是我第二天遇到此错误。赞赏任何见解。谢谢

解决方法

为什么不使用内置的Microsoft Azure Resource Manager凭据?

但具体来说,您的错误似乎是由于azure_rm广告资源插件无法验证您的inventories/development/hosts.yml而引起的。如azure_rm_inventory synopsis中所述:

需要一个名称以'azure_rm。(yml | yaml)'结尾的YAML配置文件

,

我知道已经过了一段时间,但我遇到了同样的问题并使用此解决方案:

注意:

  • 您可以在 Tower/awx 中创建标准 Azure RM 凭据 仅限此

  • 发生在我身上的 AWX 不需要 Pay Tower。

      - name : Setting Azure ARM credential facts
        set_fact:
            client_id:  "{{ lookup('env','AZURE_CLIENT_ID') }}"
            clent_secret: "{{ lookup('env','AZURE_SECRET') }}"
            tenant: "{{ lookup('env','AZURE_TENANT') }}"
            subscription: "{{ lookup('env','AZURE_SUBSCRIPTION_ID') }}"
        no_log: true