Ansible aws_ec2清单从不匹配主机组

问题描述 投票:0回答:1

所以首先,我可能在这里错过了一些非常简单的东西,但我看不到它。我正在尝试使用带有aws_ec2库存插件的ansible拉动,以使用打包程序在AWS的EC2实例上运行。我有以下清单文件:

plugin: aws_ec2
regions:
  - eu-west-1
  - eu-west-2
keyed_groups:
  - key: tags['role']
    prefix: enc
filters:
  instance-state-name: running
  tag:ami: "true

并且当我运行ansible-inventory -i /tmp/ansible/inventories/dev/ami_inventory_aws_ec2.yml --list时,得到以下组:

"all": {
        "children": [
            "aws_ec2",
            "enc_web",
            "ungrouped"
        ]
    },
    "aws_ec2": {
        "hosts": [
            "ip-10-93-66-209.eu-west-1.compute.internal"
        ]
    },
    "enc_web": {
        "hosts": [
            "ip-10-93-66-209.eu-west-1.compute.internal"
        ]
    }

这是我期望看到的。然后在我的剧本中有以下内容:

---
- import_playbook: bootstrap.yml

- hosts: enc_web
  gather_facts: True
  roles:
    - name: enc.base
....

[此时,我认为运行ansible-pullansible-playblook有或没有--limit enc_web ansible都会匹配组名并运行,但我却得到了

[WARNING]: Could not match supplied host pattern, ignoring: ami-aws-web-01
ERROR! Specified hosts and/or --limit does not match any hosts

我是否在这里缺少一些基本的东西?是否应针对该组名称中的所有主机运行?

我完整的命令是:

ansible-pull [email protected]:XXXXX/ansible.git --accept-host-key --directory=/tmp/ansible --full --checkout=web --private-key=/home/ubuntu/.ssh/ansible/ansible -e ami=true -e region=eu-west-1 --vault-password-file=~/.ssh/ansible/dev --inventory-file=/tmp/ansible/inventories/dev/ami_inventory_aws_ec2.yml playbooks/web.yml --limit enc_web
ansible ansible-inventory ansible-pull
1个回答
0
投票

将清单文件更改为:

plugin: aws_ec2
regions:
 - eu-west-1
 - eu-west-2
keyed_groups:
 - key: tags['role']
    prefix: enc
filters:
  instance-state-name: running
  tag:ami: "true"
hostnames:
 - tag:Name

然后将主机名设为需要匹配的名称。

© www.soinside.com 2019 - 2024. All rights reserved.