首页 > 解决方案 > 使用 Azure 动态清单时 Playbook 失败

问题描述

正如标题所示,我正在使用 Azure 动态清单文件,并且在针对收集的清单运行剧本时遇到问题。

我正在使用 Ansible 2.9.1 并使用此处找到的说明来设置清单文件。

$ ansible --version
ansible 2.9.1
config file = None
configured module search path = ['/home/myuser/.ansible/plugins/modules', 
'/usr/share/ansible/plugins/modules']
ansible python module location = /home/myuser/.local/lib/python3.6/site-packages/ansible
executable location = /home/myuser/.local/bin/ansible
python version = 3.6.9 (default, Sep 11 2019, 16:40:19) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]

我的库存文件:

plugin: azure_rm
include_vm_resource_groups:
- mytestrg
auth_source: cli
cloud_environment: AzureUSGovernment

hostvar_expressions:
ansible_connection: "'winrm'" 
ansible_user: "'azureuser"
ansible_password: "'Password1'"
ansible_winrm_server_cert_validation: "'ignore'"

keyed_groups:
- prefix: some_tag
key: tags.sometag | default('none')

exclude_host_filters:
- powerstate != 'running'

使用清单文件时,简单的临时命令(如 ping)会成功。我无法开始工作的是针对它运行一个剧本。

我的剧本:

- hosts: all
  name: Run whoami
  tasks:
  - win_command: whoami
    register: whoami_out

- debug:
    var: whoami_out

我用来运行剧本的命令:

ansible-playbook -i ./inventory_azure_rm.yaml whoami.yaml

无论我将剧本针对的主机是什么,它都失败了:

[警告]:无法匹配提供的主机模式,忽略:playbooks/whoami.yaml

[警告]:没有匹配的主机,无事可做

关于如何克服这个问题的任何建议?我感谢任何帮助!

标签: azureansibleansible-inventory

解决方案


推荐阅读