[英]Ansible inventory.aws_ec2.yml tags
Can someone please explain how to defined value in the inventory.aws_ec2.yml file?有人可以解释一下如何在 inventory.aws_ec2.yml 文件中定义值吗?
I want to execute ansible-playbook on the below mentiond tags instances.我想在下面提到的标签实例上执行 ansible-playbook。 Where I need to defined Environment:stage in inventory.aws_ec2.yml.我需要在 inventory.aws_ec2.yml 中定义 Environment:stage 的地方。 ie in key or in prefix?即在键或前缀?
tags:
Environment: stage
Below is inventory.aws_ec2.yml file.下面是 inventory.aws_ec2.yml 文件。
plugin: aws_ec2
regions:
- us-east-2
- us-west-2
keyed_groups:
# Add hosts to tag name groups
# - key: tags.Role
# prefix: role_
# separator: ""
- key: tags.Environment
prefix: stage
separator: ""
When you use key: tags.Environment
by each different value of this tag will be created a group in ansible, prefix
is to add a prefix to the name of each of groups created in ansible (I recommend you in this case use "Environment"
) and separator
is to add characters between the prefix and the value of the tags (by default is "_").当你使用key: tags.Environment
时,这个标签的每一个不同的值都会在 ansible 中创建一个组, prefix
是在 ansible 中创建的每个组的名称添加一个前缀(我建议你在这种情况下使用"Environment"
) 和separator
是在标签的前缀和值之间添加字符(默认为“_”)。 A way to write your aws_ec2.yml is一种编写 aws_ec2.yml 的方法是
plugin: aws_ec2
regions:
- us-east-2
- us-west-2
keyed_groups:
- key: tags.Environment
prefix: Environment
separator: "_"
For example, if you have 4 ec2 instances with tag: Environment=stage and 2 ec2 instances with tag: Environment=prod, you'll have two groups in ansible, Environment_stage
and Environment_prod
then you could create your playbook in this way例如,如果您有 4 个带标签的 ec2 实例:Environment=stage 和 2 个带标签的 ec2 实例:Environment=prod,您将在 ansible、 Environment_stage
和Environment_prod
中有两个组,那么您可以通过这种方式创建您的剧本
- name: Testing my groups
hosts: Environment_stage
gather_facts: yes
tasks:
- name: Debug my ec2 instances
debug:
msg: "hostname: {{ ansible_hostname }}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.