简体   繁体   English

Ansible inventory.aws_ec2.yml 标签

[英]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_stageEnvironment_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.

相关问题 AWS Ansible 动态清单针对主机或使用多个标签制作动态组 - AWS Ansible Dynamic Inventory targeting hosts or making dynamic groups using multiple tags 我可以在 community.aws.ec2_vpc_route_table Ansible 模块中使用 group_vars/all.yml 吗? - Can I use group_vars/all.yml in community.aws.ec2_vpc_route_table Ansible Module? 使用 boto3 获取多个 aws 帐户 ec2 库存 - Get multiple aws account ec2 inventory using boto3 使用 ansible was_ec2 动态清单插件到达堡垒主机后面的盒子时出现问题 - Issue reaching boxes behind a bastion host with ansible was_ec2 dynamic inventory plugin Ansible:ec2 aws 插件 - 如何根据 aws_profile 将 ec2 主机关联到 ansible 组? - Ansible: ec2 aws plugin - How to associate ec2 host to ansible group based on aws_profile? 在 aws 命令之间格式化 ansible 中的 json 标签 - formatting json tags in ansible between aws commands Ansible aws_ec2 插件集 ansible_host:来自基于“描述:”的多个私有 ip - Ansible aws_ec2 plugin set ansible_host: from multiple private ips based on 'description:' 如何在 Terraform 中为 AWS EC2 应用不同的 TAG - How to apply different TAGs for AWS EC2 in Terraform 在 AWS CloudFormation 中使用 EC2 实例创建的卷上的标签 - Tags on volumes created with EC2 instances in AWS CloudFormation 使用 CLI 的带空格的 AWS EC2 和 AMI 标签 - AWS EC2 and AMI tags with spaces using CLI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM