无法使Ansible playbook在初始运行时运行
我在Ansible 2.9中遇到了一个问题,在创建ec2实例之后,在它第一次尝试使用我创建的playbook在该实例上运行apt update之前,我遇到了以下错误:无法使Ansible playbook在初始运行时运行,ansible,ansible-2.x,Ansible,Ansible 2.x,我在Ansible 2.9中遇到了一个问题,在创建ec2实例之后,在它第一次尝试使用我创建的playbook在该实例上运行apt update之前,我遇到了以下错误: [WARNING]: Could not match supplied host pattern, ignoring: tag_type_master 但是,当我第二次运行它时,它确实找到了与该标记匹配的主机,并继续运行apt更新和其他playbook任务 以下是我正在运行的命令: ansible-playbook deploy
[WARNING]: Could not match supplied host pattern, ignoring: tag_type_master
但是,当我第二次运行它时,它确实找到了与该标记匹配的主机,并继续运行apt更新和其他playbook任务
以下是我正在运行的命令:
ansible-playbook deploy.yaml --private-key ../../../../../Downloads/XXXXXXX.pem --inventory=inventory_aws_ec2.yaml
这是我的deploy.yaml文件:
- name: Build out AWS Infrastructure
hosts: localhost
connection: local
gather_facts: False
roles:
- role: aws
- name: Setup Master
hosts: tag_type_master
remote_user: ubuntu
become: yes
roles:
- role: master
- name: Build Master AMI
hosts: localhost
connection: local
roles:
- role: master_ami
plugin: aws_ec2
regions:
- us-east-2
keyed_groups:
- key: tags.type
prefix: tag_type_
separator: ""
hostnames:
- dns-name
compose:
ansible_host: dns-name
cache: yes
cache_plugin: memory
cache_timeout: 7200
cache_prefix: aws_ec2
这是我的inventory\u aws\u ec2.yaml文件:
- name: Build out AWS Infrastructure
hosts: localhost
connection: local
gather_facts: False
roles:
- role: aws
- name: Setup Master
hosts: tag_type_master
remote_user: ubuntu
become: yes
roles:
- role: master
- name: Build Master AMI
hosts: localhost
connection: local
roles:
- role: master_ami
plugin: aws_ec2
regions:
- us-east-2
keyed_groups:
- key: tags.type
prefix: tag_type_
separator: ""
hostnames:
- dns-name
compose:
ansible_host: dns-name
cache: yes
cache_plugin: memory
cache_timeout: 7200
cache_prefix: aws_ec2
这是我的ansible.cfg文件:
[defaults]
host_key_checking = False
fact_caching = memory
cache_timeout = 3600
[inventory_aws_ec2]
enable_plugins = aws_ec2
cache = yes
有什么我遗漏的吗?提前谢谢
更新:
我还能够运行ansible inventory命令而不出现任何问题,并且它可以提供预期的结果:
ansible-inventory -i inventory_aws_ec2.yaml --graph
@all:
|--@aws_ec2:
| |--ec2-XX-XX-XX-XX.us-east-2.compute.amazonaws.com
| |--ec2-XX-XX-XX-XX.us-east-2.compute.amazonaws.com
| |--ec2-XX-XX-XX-XX.us-east-2.compute.amazonaws.com
| |--ec2-XX-XX-XX-XX.us-east-2.compute.amazonaws.com
| |--ec2-XX-XX-XX-XX.us-east-2.compute.amazonaws.com
| |--ec2-XX-XX-XX-XX.us-east-2.compute.amazonaws.com
|--@tag_type_master:
| |--ec2-XX-XX-XX-XX.us-east-2.compute.amazonaws.com
|--@ungrouped:
在您随tag master提供的清单文件中,我没有看到任何主机 应该是
[master]
127.0.0.1 ansible_connection=local
怀疑时间同步问题 通常,该实例需要一些时间来启动和运行。 您可以尝试为任务添加睡眠/等待,并确保实例已启动 在你做主人之前先跑。 无论如何,请分享结果
谢谢我想明白了。我需要添加一个刷新库存步骤:
谢谢你的回复,但结果是一样的。[警告]:无法匹配提供的主机模式,忽略:tag\u type\u master谢谢。我在上面添加了一个更新,但我不认为需要添加主机,因为我能够运行ansible inventory命令而没有任何问题,并且得到了预期的结果。谢谢。它会等待实例启动。在实例构建时,我还运行了ansible inventory命令,实例确实如预期的那样出现了。这仍然不起作用。当我在创建ec2的过程中运行ansible inventory时,我得到了预期的结果,因此不确定等待是否会起到任何作用,但感谢您的跟进。