首页 > 解决方案 > 如何让 awx 使用 azure_rm.yml 而不是 ini 版本?

问题描述

我需要使用 azure_rm 的“plugin/azure_rm.yml”版本而不是旧的/已弃用的“script/azure_rm.ini”来收集 Azure 中的动态清单,特别是因为我们需要将规模集中的 VM 包含在清单中。我怎样才能做到这一点?

标签: ansible-inventoryansible-toweransible-awx

解决方案


您可以使用清单脚本,该脚本(再次)调用 ansible-inventory,并通过以下方式创建配置文件heredoc

#!/usr/bin/env bash
cat > azure_rm.yml <<HEREDOC
---
plugin: azure_rm
include_vmss_resource_groups:
- '*'
hostvar_expressions:
  ansible_host: private_ipv4_addresses | first
plain_host_names: true
keyed_groups:
# places each host in a group named 'tag_(tag name)_(tag value)' for each tag on a VM.
- prefix: tag
  key: tags
# places each host in a group named 'azure_loc_(location name)', depending on the VM's location
- prefix: azure_loc
  key: location
# group by platform (to copy prefix from ec2.py), eg: platform_windows
- prefix: platform
  key: os_disk.operating_system_type
HEREDOC
ansible-inventory -i azure_rm.yml --list
rm azure_rm.yml

所以它实际上是有 ansible-inventory 调用 ansible-inventory,但有不同的论点。请注意,为了获得正确订阅的库存,您必须创建一个使用的凭证副本,并带有所需的订阅 ID;您似乎无法通过 yml 环境参数覆盖 AZURE_SUBSCRIPTION_ID 。


推荐阅读