简体   繁体   English

Ansible ec2动态广告资源存在问题

[英]Trouble with Ansible ec2 dynamic inventory

I'm using ansible to configure and deploy several servers in ec2. 我正在使用ansible在ec2中配置和部署多台服务器。 Since these servers are frequently changing I'd like to use dynamic inventory. 由于这些服务器经常更改,因此我想使用动态清单。 I have set up ec2.py and ec2.ini in my jenkins server (this is where the ansible scripts are run) but am running into an issue when I run the playbook: 我已经在jenkins服务器中设置了ec2.py和ec2.ini(这是运行ansible脚本的位置),但是在运行剧本时遇到了问题:

ERROR! Specified --limit does not match any hosts

Which clearly means that my hosts are not being selected correctly. 这显然意味着我的主机没有被正确选择。 When I run: 当我跑步时:

./ec2.py --list >> aws_example.json

everything looks good in aws_example.json . 一切都在aws_example.json看起来不错。

I'm trying to select servers based on two tags, Name and environment. 我正在尝试根据两个标签(名称和环境)选择服务器。 For example, I have a server with a 'Name' tag of 'api' and an 'environment' tag of 'production'. 例如,我有一台服务器,其“名称”标签为“ api”,而“环境”标签为“生产”。


I've set up the destination_format_tags like so: 我已经这样设置了destination_format_tags

destination_format_tags = Name,environment

and run ansible as follows: 并按以下方式运行ansible:

ansible-playbook site.yml -i ec2.py -l api

I've also tried changing the hostname_variable : 我也尝试过更改hostname_variable

hostname_variable = tag_Name.tag_environment

and running the command like so: 并像这样运行命令:

ansible-playbook site.yml -i ec2.py -l api.production

Additionally, I've also tried using only one tag with the hostname_variable : 此外,我还尝试过仅将一个标签与hostname_variable

hostname_variable = tag_Name

and running the command like so: 并像这样运行命令:

ansible-playbook site.yml -i ec2.py -l api

None of these configurations work. 这些配置均无效。 I'm also unable to find much documentation about these setting so I'm not sure how to correctly configure it. 我也找不到太多有关这些设置的文档,所以我不确定如何正确配置它。 Can anyone point me in the right direction? 谁能指出我正确的方向?

So the problem was how I was representing my host names in my playbook. 所以问题是我如何在剧本中表示主机名。 Setting the hostname variable was the right thing to do: 设置主机名变量是正确的做法:

hostname_variable = tag_Name

And here's how to represent it in the playbook: 这是在剧本中的表达方式:

- name: configure and deploy api servers
  hosts: tag_Name_api
  remote_user: ec2-user
  sudo: true

  roles:
  - java
  - nginx
  - api

Additionally, it'll need to be called like so: 另外,它需要像这样被调用:

ansible-playbook site.yml -i ec2.py -l tag_Name_api

Make sure to change special characters such as . 确保更改特殊字符,例如. or - to _ . 或者-_

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM