通过 ansible 创建实例和标记 [英] Creating instance and tagging via ansible

查看:38
本文介绍了通过 ansible 创建实例和标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ansible 在不同的 AZ 创建实例,我在这里面临两个问题:

<块引用>

  1. 我需要在 AZ 中创建 3 个实例,但下面的播放创建了 6 个实例,其中 3 个实例在 AZ-a 中,3 个实例在 AZ-b 中
  2. 我也在尝试标记这些实例,在创建它们时使用一个序列,但我无法传递/遍历 json返回.

以下是剧目:

---- 名称:创建 ES 主节点实例ec2:key_name: "{{ aws_key_name }}"实例类型:{{ aws_instance_type }}"图像:{{ aws_ami }}"等待:是的等待超时:500计数:{{ master_instance_count }}"实例标签:名称:{{ master_tag_name }}"卷:- 设备名称:/dev/sda1音量类型:gp2卷大小:100vpc_subnet_id: "{{ subnet_ids[item] }}"区域:{{ aws_region }}"组:{{ aws_sec_group_name }}"with_items:- 一种- 乙注册:ec2_details- 名称:生成用于标记的序列 ID调试:味精={{项目}}"with_sequence: start="{{ startindex }}" end="{{ master_instance_count }}" 格式=%02d寄存器:序列- name:调试变量名调试:变量:ec2_details#msg={{ ec2_details |type_debug }}- 名称:将创建的实例标记为 Mastersec2_tag:区域:{{ aws_region }}"资源:{{ item.0.id }}"标签:名称:{{ master_tag_name }}-{{ item.1.msg }}"with_together:- {{ ec2_details.results.instance_ids }}"- "{{ sequence.results }}"- 名称:将实例添加到本地清单文件本地操作:lineinfile path="~/ansible-environments/hosts"insertafter="\[esmaster\]"line="{{ item.private_ip }}"状态=现在"with_items: "{{ ec2_details.results.instances }}"

我不确定问题 1 是如何发生的以及如何解决,对于第二个问题,我需要帮助遍历结果,以便我可以在文件中标记和创建库存.

调试输出

TASK [provision_es_cluster : 调试变量名] *************************************************************************************************任务路径:/home/nishantsingh/daas-ansible-playbooks/roles/provision_es_cluster/tasks/master_node.yml:29好的:[本地主机] =>{ec2_details":{改变":真的,"msg": "所有项目已完成",结果": [{_ansible_item_result":真,_ansible_no_log":假,_ansible_parsed":真,改变":真的,失败":错误,instance_ids":["i-05aee7d659a14f6c8","i-0aa09975bdb96b9aa",i-094b151b09ae19b27"],实例":[{"ami_launch_index": "2","架构": "x86_64",block_device_mapping":{/dev/sda1":{delete_on_termination":假,状态":附加","volume_id": "vol-08b2167e65a8047ea"}},"dns_name": "",ebs_optimized":假,组":{"sg-1e3c9d79": "elasticsearch-mayassar-production","sg-4659bc3f": "Test_nishant","sg-86018ce2": "mayassar-es-external"},"hypervisor": "xen","id": "i-05aee7d659a14f6c8","image_id": "ami-325d2e4e","instance_type": "m4.4xlarge",内核":空,"key_name": "ansible 管理","launch_time": "2018-01-30T05:07:42.000Z","placement": "ap-southeast-1a","private_dns_name": "ip-172-16-14-80.ap-southeast-1.compute.internal","private_ip": "172.16.14.80","public_dns_name": "",public_ip":空,虚拟磁盘":空,"region": "ap-southeast-1","root_device_name": "/dev/sda1","root_device_type": "ebs",状态":运行",状态代码":16,标签":{名称":Kill-master-es"},租赁":默认","virtualization_type": "hvm"},{"ami_launch_index": "1","架构": "x86_64",block_device_mapping":{/dev/sda1":{delete_on_termination":假,状态":附加",volume_id":vol-036062675c6119993"}},"dns_name": "",ebs_optimized":假,组":{"sg-1e3c9d79": "elasticsearch-mayassar-production","sg-4659bc3f": "Test_nishant","sg-86018ce2": "mayassar-es-external"},"hypervisor": "xen","id": "i-0aa09975bdb96b9aa","image_id": "ami-325d2e4e","instance_type": "m4.4xlarge",内核":空,"key_name": "ansible 管理","launch_time": "2018-01-30T05:07:42.000Z","placement": "ap-southeast-1a","private_dns_name": "ip-172-16-14-176.ap-southeast-1.compute.internal","private_ip": "172.16.14.176","public_dns_name": "",public_ip":空,虚拟磁盘":空,"region": "ap-southeast-1","root_device_name": "/dev/sda1","root_device_type": "ebs",状态":运行",状态代码":16,标签":{名称":Kill-master-es"},租赁":默认","virtualization_type": "hvm"},{"ami_launch_index": "0","架构": "x86_64",block_device_mapping":{/dev/sda1":{delete_on_termination":假,状态":附加",volume_id":vol-0566ea20a2ef4d40b"}},"dns_name": "",ebs_optimized":假,组":{"sg-1e3c9d79": "elasticsearch-mayassar-production","sg-4659bc3f": "Test_nishant","sg-86018ce2": "mayassar-es-external"},"hypervisor": "xen","id": "i-094b151b09ae19b27","image_id": "ami-325d2e4e","instance_type": "m4.4xlarge",内核":空,"key_name": "ansible 管理","launch_time": "2018-01-30T05:07:42.000Z","placement": "ap-southeast-1a","private_dns_name": "ip-172-16-14-171.ap-southeast-1.compute.internal","private_ip": "172.16.14.171","public_dns_name": "",public_ip":空,虚拟磁盘":空,"region": "ap-southeast-1","root_device_name": "/dev/sda1","root_device_type": "ebs",状态":运行",状态代码":16,标签":{名称":Kill-master-es"},租赁":默认","virtualization_type": "hvm"}],调用":{模块参数":{assign_public_ip":假,aws_access_key":空,aws_secret_key":空,计数":3,count_tag":空,ebs_optimized":假,ec2_url":空,精确计数":空,团体": ["mayassar-es-external","elasticsearch-mayassar-生产",Test_nishant"],group_id":空,id":空,"image": "ami-325d2e4e",instance_ids":空,instance_initiated_shutdown_behavior":空,instance_profile_name":空,实例标签":{名称":Kill-master-es"},"instance_type": "m4.4xlarge",内核":空,"key_name": "ansible 管理",监控":假,网络接口":空,placement_group":空,private_ip":空,个人资料":空,虚拟磁盘":空,"region": "ap-southeast-1",security_token":空,source_dest_check":真,spot_launch_group":空,现货价格":空,"spot_type": "一次性","spot_wait_timeout": "600","状态": "现在",租赁":默认",终止保护":空,用户数据":空,validate_certs":真,卷":[{"device_name": "/dev/sda1",volume_size":100,volume_type":gp2"}],"vpc_subnet_id": "subnet-9c3e38f8",等待":真的,"wait_timeout": "500",区域":空}},"item": "a",tagged_instances":[]},{_ansible_item_result":真,_ansible_no_log":假,_ansible_parsed":真,改变":真的,失败":错误,instance_ids":["i-08d33c0bda075f2a7","i-0e05e337933456b48",i-0aeca61abca10406e"],实例":[{"ami_launch_index": "0","架构": "x86_64",block_device_mapping":{/dev/sda1":{delete_on_termination":假,状态":附加","volume_id": "vol-06b5f8518cd368c12"}},"dns_name": "",ebs_optimized":假,组":{"sg-1e3c9d79": "elasticsearch-mayassar-production","sg-4659bc3f": "Test_nishant","sg-86018ce2": "mayassar-es-external"},"hypervisor": "xen","id": "i-08d33c0bda075f2a7","image_id": "ami-325d2e4e","instance_type": "m4.4xlarge",内核":空,"key_name": "ansible 管理","launch_time": "2018-01-30T05:07:58.000Z","placement": "ap-southeast-1b","private_dns_name": "ip-172-16-9-206.ap-southeast-1.compute.internal","private_ip": "172.16.9.206","public_dns_name": "",public_ip":空,虚拟磁盘":空,"region": "ap-southeast-1","root_device_name": "/dev/sda1","root_device_type": "ebs",状态":运行",状态代码":16,标签":{名称":Kill-master-es"},租赁":默认","virtualization_type": "hvm"},{"ami_launch_index": "1","架构": "x86_64",block_device_mapping":{/dev/sda1":{delete_on_termination":假,状态":附加",volume_id":vol-0b9cf0da059d23238"}},"dns_name": "",ebs_optimized":假,组":{"sg-1e3c9d79": "elasticsearch-mayassar-production","sg-4659bc3f": "Test_nishant","sg-86018ce2": "mayassar-es-external"},"hypervisor": "xen","id": "i-0e05e337933456b48","image_id": "ami-325d2e4e","instance_type": "m4.4xlarge",内核":空,"key_name": "ansible 管理","launch_time": "2018-01-30T05:07:58.000Z","placement": "ap-southeast-1b","private_dns_name": "ip-172-16-9-141.ap-southeast-1.compute.internal","private_ip": "172.16.9.141","public_dns_name": "",public_ip":空,虚拟磁盘":空,"region": "ap-southeast-1","root_device_name": "/dev/sda1","root_device_type": "ebs",状态":运行",状态代码":16,标签":{名称":Kill-master-es"},租赁":默认","virtualization_type": "hvm"},{"ami_launch_index": "2","架构": "x86_64",block_device_mapping":{/dev/sda1":{delete_on_termination":假,状态":附加",volume_id":vol-06057ca9f82fb8c53"}},"dns_name": "",ebs_optimized":假,组":{"sg-1e3c9d79": "elasticsearch-mayassar-production","sg-4659bc3f": "Test_nishant","sg-86018ce2": "mayassar-es-external"},"hypervisor": "xen","id": "i-0aeca61abca10406e","image_id": "ami-325d2e4e","instance_type": "m4.4xlarge",内核":空,"key_name": "ansible 管理","launch_time": "2018-01-30T05:07:58.000Z","placement": "ap-southeast-1b","private_dns_name": "ip-172-16-9-201.ap-southeast-1.compute.internal","private_ip": "172.16.9.201","public_dns_name": "",public_ip":空,虚拟磁盘":空,"region": "ap-southeast-1","root_device_name": "/dev/sda1","root_device_type": "ebs",状态":运行",状态代码":16,标签":{名称":Kill-master-es"},租赁":默认","virtualization_type": "hvm"}],调用":{模块参数":{assign_public_ip":假,aws_access_key":空,aws_secret_key":空,计数":3,count_tag":空,ebs_optimized":假,ec2_url":空,精确计数":空,团体": ["mayassar-es-external","elasticsearch-mayassar-生产",Test_nishant"],group_id":空,id":空,"image": "ami-325d2e4e",instance_ids":空,instance_initiated_shutdown_behavior":空,instance_profile_name":空,实例标签":{名称":Kill-master-es"},"instance_type": "m4.4xlarge",内核":空,"key_name": "ansible 管理",监控":假,网络接口":空,placement_group":空,private_ip":空,个人资料":空,虚拟磁盘":空,"region": "ap-southeast-1",security_token":空,source_dest_check":真,spot_launch_group":空,现货价格":空,"spot_type": "一次性","spot_wait_timeout": "600","状态": "现在",租赁":默认",termination_protection":空,用户数据":空,validate_certs":真,卷":[{"device_name": "/dev/sda1",volume_size":100,volume_type":gp2"}],"vpc_subnet_id": "subnet-88d171ff",等待":真的,"wait_timeout": "500",区域":空}},"项目": "b",tagged_instances":[]}]}}

请帮忙

解决方案

根据你的剧本输出和你发布的剧本,我对 AWS 不太了解.

 "调用": {模块参数":{assign_public_ip":假,aws_access_key":空,aws_secret_key":空,计数":3,count_tag":空,ebs_optimized":假,ec2_url":空,精确计数":空,团体": ["mayassar-es-external","elasticsearch-mayassar-生产",Test_nishant"],

这里的 count 是 3,所以它在两个区域创建了三个实例ab

如果要遍历输出可以用下面的方法

http://docs.ansible.com/ansible/latest/playbooks_loops.html#looping-over-subelements

I am using ansible to create instance in different AZ , i am facing two issues here:

  1. I need to create 3 instances in AZ , but the below play creates 6 instances such that 3 instances in AZ-a and 3 in AZ-b
  2. I am trying to tag these instances as well, using a sequence as they are being created, but i am not able to pass/traverse the json returned.

Here are the plays:

---
  - name: Create ES Master Node instances
    ec2:
      key_name: "{{ aws_key_name }}"
      instance_type: "{{ aws_instance_type }}"
      image: "{{ aws_ami }}"
      wait: yes
      wait_timeout: 500
      count: "{{ master_instance_count }}"
      instance_tags:
        Name: "{{ master_tag_name }}"
      volumes:
        - device_name: /dev/sda1
          volume_type: gp2
          volume_size: 100
      vpc_subnet_id: "{{ subnet_ids[item] }}"
      region: "{{ aws_region }}"
      group: "{{ aws_sec_group_name }}"
    with_items:
      - a
      - b
    register: ec2_details

  - name: Generate Sequence ID for tagging
    debug: msg="{{ item }}"
    with_sequence: start="{{ startindex }}" end="{{ master_instance_count }}" format=%02d
    register: sequence

  - name: Debug the variable name
    debug:
          var: ec2_details
          #msg={{ ec2_details | type_debug }}

  - name: Tag Created instance as Masters
    ec2_tag:
      region: "{{ aws_region }}"
      resource: "{{ item.0.id }}"
      tags:
        Name: "{{ master_tag_name }}-{{ item.1.msg }}"
    with_together:
      - "{{ ec2_details.results.instance_ids }}"
      - "{{ sequence.results }}"

  - name: Add Instances to local inventory file
    local_action:
      lineinfile path="~/ansible-environments/hosts"
        insertafter="\[esmaster\]"
        line="{{ item.private_ip }}"
        state="present"
    with_items: "{{ ec2_details.results.instances }}"

I am not sure how is issue 1 happening and how to solve, and for the 2nd i need help in traversing the result so that i can tag and create inventory in a file.

OUTPUT of DEBUG

TASK [provision_es_cluster : Debug the variable name] *****************************************************************************************
task path: /home/nishantsingh/daas-ansible-playbooks/roles/provision_es_cluster/tasks/master_node.yml:29
ok: [localhost] => {
    "ec2_details": {
        "changed": true, 
        "msg": "All items completed", 
        "results": [
            {
                "_ansible_item_result": true, 
                "_ansible_no_log": false, 
                "_ansible_parsed": true, 
                "changed": true, 
                "failed": false, 
                "instance_ids": [
                    "i-05aee7d659a14f6c8", 
                    "i-0aa09975bdb96b9aa", 
                    "i-094b151b09ae19b27"
                ], 
                "instances": [
                    {
                        "ami_launch_index": "2", 
                        "architecture": "x86_64", 
                        "block_device_mapping": {
                            "/dev/sda1": {
                                "delete_on_termination": false, 
                                "status": "attached", 
                                "volume_id": "vol-08b2167e65a8047ea"
                            }
                        }, 
                        "dns_name": "", 
                        "ebs_optimized": false, 
                        "groups": {
                            "sg-1e3c9d79": "elasticsearch-mayassar-production", 
                            "sg-4659bc3f": "Test_nishant", 
                            "sg-86018ce2": "mayassar-es-external"
                        }, 
                        "hypervisor": "xen", 
                        "id": "i-05aee7d659a14f6c8", 
                        "image_id": "ami-325d2e4e", 
                        "instance_type": "m4.4xlarge", 
                        "kernel": null, 
                        "key_name": "ansible-managed", 
                        "launch_time": "2018-01-30T05:07:42.000Z", 
                        "placement": "ap-southeast-1a", 
                        "private_dns_name": "ip-172-16-14-80.ap-southeast-1.compute.internal", 
                        "private_ip": "172.16.14.80", 
                        "public_dns_name": "", 
                        "public_ip": null, 
                        "ramdisk": null, 
                        "region": "ap-southeast-1", 
                        "root_device_name": "/dev/sda1", 
                        "root_device_type": "ebs", 
                        "state": "running", 
                        "state_code": 16, 
                        "tags": {
                            "Name": "Kill-master-es"
                        }, 
                        "tenancy": "default", 
                        "virtualization_type": "hvm"
                    }, 
                    {
                        "ami_launch_index": "1", 
                        "architecture": "x86_64", 
                        "block_device_mapping": {
                            "/dev/sda1": {
                                "delete_on_termination": false, 
                                "status": "attached", 
                                "volume_id": "vol-036062675c6119993"
                            }
                        }, 
                        "dns_name": "", 
                        "ebs_optimized": false, 
                        "groups": {
                            "sg-1e3c9d79": "elasticsearch-mayassar-production", 
                            "sg-4659bc3f": "Test_nishant", 
                            "sg-86018ce2": "mayassar-es-external"
                        }, 
                        "hypervisor": "xen", 
                        "id": "i-0aa09975bdb96b9aa", 
                        "image_id": "ami-325d2e4e", 
                        "instance_type": "m4.4xlarge", 
                        "kernel": null, 
                        "key_name": "ansible-managed", 
                        "launch_time": "2018-01-30T05:07:42.000Z", 
                        "placement": "ap-southeast-1a", 
                        "private_dns_name": "ip-172-16-14-176.ap-southeast-1.compute.internal", 
                        "private_ip": "172.16.14.176", 
                        "public_dns_name": "", 
                        "public_ip": null, 
                        "ramdisk": null, 
                        "region": "ap-southeast-1", 
                        "root_device_name": "/dev/sda1", 
                        "root_device_type": "ebs", 
                        "state": "running", 
                        "state_code": 16, 
                        "tags": {
                            "Name": "Kill-master-es"
                        }, 
                        "tenancy": "default", 
                        "virtualization_type": "hvm"
                    }, 
                    {
                        "ami_launch_index": "0", 
                        "architecture": "x86_64", 
                        "block_device_mapping": {
                            "/dev/sda1": {
                                "delete_on_termination": false, 
                                "status": "attached", 
                                "volume_id": "vol-0566ea20a2ef4d40b"
                            }
                        }, 
                        "dns_name": "", 
                        "ebs_optimized": false, 
                        "groups": {
                            "sg-1e3c9d79": "elasticsearch-mayassar-production", 
                            "sg-4659bc3f": "Test_nishant", 
                            "sg-86018ce2": "mayassar-es-external"
                        }, 
                        "hypervisor": "xen", 
                        "id": "i-094b151b09ae19b27", 
                        "image_id": "ami-325d2e4e", 
                        "instance_type": "m4.4xlarge", 
                        "kernel": null, 
                        "key_name": "ansible-managed", 
                        "launch_time": "2018-01-30T05:07:42.000Z", 
                        "placement": "ap-southeast-1a", 
                        "private_dns_name": "ip-172-16-14-171.ap-southeast-1.compute.internal", 
                        "private_ip": "172.16.14.171", 
                        "public_dns_name": "", 
                        "public_ip": null, 
                        "ramdisk": null, 
                        "region": "ap-southeast-1", 
                        "root_device_name": "/dev/sda1", 
                        "root_device_type": "ebs", 
                        "state": "running", 
                        "state_code": 16, 
                        "tags": {
                            "Name": "Kill-master-es"
                        }, 
                        "tenancy": "default", 
                        "virtualization_type": "hvm"
                    }
                ], 
                "invocation": {
                    "module_args": {
                        "assign_public_ip": false, 
                        "aws_access_key": null, 
                        "aws_secret_key": null, 
                        "count": 3, 
                        "count_tag": null, 
                        "ebs_optimized": false, 
                        "ec2_url": null, 
                        "exact_count": null, 
                        "group": [
                            "mayassar-es-external", 
                            "elasticsearch-mayassar-production", 
                            "Test_nishant"
                        ], 
                        "group_id": null, 
                        "id": null, 
                        "image": "ami-325d2e4e", 
                        "instance_ids": null, 
                        "instance_initiated_shutdown_behavior": null, 
                        "instance_profile_name": null, 
                        "instance_tags": {
                            "Name": "Kill-master-es"
                        }, 
                        "instance_type": "m4.4xlarge", 
                        "kernel": null, 
                        "key_name": "ansible-managed", 
                        "monitoring": false, 
                        "network_interfaces": null, 
                        "placement_group": null, 
                        "private_ip": null, 
                        "profile": null, 
                        "ramdisk": null, 
                        "region": "ap-southeast-1", 
                        "security_token": null, 
                        "source_dest_check": true, 
                        "spot_launch_group": null, 
                        "spot_price": null, 
                        "spot_type": "one-time", 
                        "spot_wait_timeout": "600", 
                        "state": "present", 
                        "tenancy": "default", 
                        "termination_protection": null, 
                        "user_data": null, 
                        "validate_certs": true, 
                        "volumes": [
                            {
                                "device_name": "/dev/sda1", 
                                "volume_size": 100, 
                                "volume_type": "gp2"
                            }
                        ], 
                        "vpc_subnet_id": "subnet-9c3e38f8", 
                        "wait": true, 
                        "wait_timeout": "500", 
                        "zone": null
                    }
                }, 
                "item": "a", 
                "tagged_instances": []
            }, 
            {
                "_ansible_item_result": true, 
                "_ansible_no_log": false, 
                "_ansible_parsed": true, 
                "changed": true, 
                "failed": false, 
                "instance_ids": [
                    "i-08d33c0bda075f2a7", 
                    "i-0e05e337933456b48", 
                    "i-0aeca61abca10406e"
                ], 
                "instances": [
                    {
                        "ami_launch_index": "0", 
                        "architecture": "x86_64", 
                        "block_device_mapping": {
                            "/dev/sda1": {
                                "delete_on_termination": false, 
                                "status": "attached", 
                                "volume_id": "vol-06b5f8518cd368c12"
                            }
                        }, 
                        "dns_name": "", 
                        "ebs_optimized": false, 
                        "groups": {
                            "sg-1e3c9d79": "elasticsearch-mayassar-production", 
                            "sg-4659bc3f": "Test_nishant", 
                            "sg-86018ce2": "mayassar-es-external"
                        }, 
                        "hypervisor": "xen", 
                        "id": "i-08d33c0bda075f2a7", 
                        "image_id": "ami-325d2e4e", 
                        "instance_type": "m4.4xlarge", 
                        "kernel": null, 
                        "key_name": "ansible-managed", 
                        "launch_time": "2018-01-30T05:07:58.000Z", 
                        "placement": "ap-southeast-1b", 
                        "private_dns_name": "ip-172-16-9-206.ap-southeast-1.compute.internal", 
                        "private_ip": "172.16.9.206", 
                        "public_dns_name": "", 
                        "public_ip": null, 
                        "ramdisk": null, 
                        "region": "ap-southeast-1", 
                        "root_device_name": "/dev/sda1", 
                        "root_device_type": "ebs", 
                        "state": "running", 
                        "state_code": 16, 
                        "tags": {
                            "Name": "Kill-master-es"
                        }, 
                        "tenancy": "default", 
                        "virtualization_type": "hvm"
                    }, 
                    {
                        "ami_launch_index": "1", 
                        "architecture": "x86_64", 
                        "block_device_mapping": {
                            "/dev/sda1": {
                                "delete_on_termination": false, 
                                "status": "attached", 
                                "volume_id": "vol-0b9cf0da059d23238"
                            }
                        }, 
                        "dns_name": "", 
                        "ebs_optimized": false, 
                        "groups": {
                            "sg-1e3c9d79": "elasticsearch-mayassar-production", 
                            "sg-4659bc3f": "Test_nishant", 
                            "sg-86018ce2": "mayassar-es-external"
                        }, 
                        "hypervisor": "xen", 
                        "id": "i-0e05e337933456b48", 
                        "image_id": "ami-325d2e4e", 
                        "instance_type": "m4.4xlarge", 
                        "kernel": null, 
                        "key_name": "ansible-managed", 
                        "launch_time": "2018-01-30T05:07:58.000Z", 
                        "placement": "ap-southeast-1b", 
                        "private_dns_name": "ip-172-16-9-141.ap-southeast-1.compute.internal", 
                        "private_ip": "172.16.9.141", 
                        "public_dns_name": "", 
                        "public_ip": null, 
                        "ramdisk": null, 
                        "region": "ap-southeast-1", 
                        "root_device_name": "/dev/sda1", 
                        "root_device_type": "ebs", 
                        "state": "running", 
                        "state_code": 16, 
                        "tags": {
                            "Name": "Kill-master-es"
                        }, 
                        "tenancy": "default", 
                        "virtualization_type": "hvm"
                    }, 
                    {
                        "ami_launch_index": "2", 
                        "architecture": "x86_64", 
                        "block_device_mapping": {
                            "/dev/sda1": {
                                "delete_on_termination": false, 
                                "status": "attached", 
                                "volume_id": "vol-06057ca9f82fb8c53"
                            }
                        }, 
                        "dns_name": "", 
                        "ebs_optimized": false, 
                        "groups": {
                            "sg-1e3c9d79": "elasticsearch-mayassar-production", 
                            "sg-4659bc3f": "Test_nishant", 
                            "sg-86018ce2": "mayassar-es-external"
                        }, 
                        "hypervisor": "xen", 
                        "id": "i-0aeca61abca10406e", 
                        "image_id": "ami-325d2e4e", 
                        "instance_type": "m4.4xlarge", 
                        "kernel": null, 
                        "key_name": "ansible-managed", 
                        "launch_time": "2018-01-30T05:07:58.000Z", 
                        "placement": "ap-southeast-1b", 
                        "private_dns_name": "ip-172-16-9-201.ap-southeast-1.compute.internal", 
                        "private_ip": "172.16.9.201", 
                        "public_dns_name": "", 
                        "public_ip": null, 
                        "ramdisk": null, 
                        "region": "ap-southeast-1", 
                        "root_device_name": "/dev/sda1", 
                        "root_device_type": "ebs", 
                        "state": "running", 
                        "state_code": 16, 
                        "tags": {
                            "Name": "Kill-master-es"
                        }, 
                        "tenancy": "default", 
                        "virtualization_type": "hvm"
                    }
                ], 
                "invocation": {
                    "module_args": {
                        "assign_public_ip": false, 
                        "aws_access_key": null, 
                        "aws_secret_key": null, 
                        "count": 3, 
                        "count_tag": null, 
                        "ebs_optimized": false, 
                        "ec2_url": null, 
                        "exact_count": null, 
                        "group": [
                            "mayassar-es-external", 
                            "elasticsearch-mayassar-production", 
                            "Test_nishant"
                        ], 
                        "group_id": null, 
                        "id": null, 
                        "image": "ami-325d2e4e", 
                        "instance_ids": null, 
                        "instance_initiated_shutdown_behavior": null, 
                        "instance_profile_name": null, 
                        "instance_tags": {
                            "Name": "Kill-master-es"
                        }, 
                        "instance_type": "m4.4xlarge", 
                        "kernel": null, 
                        "key_name": "ansible-managed", 
                        "monitoring": false, 
                        "network_interfaces": null, 
                        "placement_group": null, 
                        "private_ip": null, 
                        "profile": null, 
                        "ramdisk": null, 
                        "region": "ap-southeast-1", 
                        "security_token": null, 
                        "source_dest_check": true, 
                        "spot_launch_group": null, 
                        "spot_price": null, 
                        "spot_type": "one-time", 
                        "spot_wait_timeout": "600", 
                        "state": "present", 
                        "tenancy": "default", 
                        "termination_protection": null, 
                        "user_data": null, 
                        "validate_certs": true, 
                        "volumes": [
                            {
                                "device_name": "/dev/sda1", 
                                "volume_size": 100, 
                                "volume_type": "gp2"
                            }
                        ], 
                        "vpc_subnet_id": "subnet-88d171ff", 
                        "wait": true, 
                        "wait_timeout": "500", 
                        "zone": null
                    }
                }, 
                "item": "b", 
                "tagged_instances": []
            }
        ]
    }
}

Please help

解决方案

I don't have good knowledge about AWS as per your output of the playbook and the playbook you posted.

           "invocation": {
                "module_args": {
                    "assign_public_ip": false, 
                    "aws_access_key": null, 
                    "aws_secret_key": null, 
                    "count": 3, 
                    "count_tag": null, 
                    "ebs_optimized": false, 
                    "ec2_url": null, 
                    "exact_count": null, 
                    "group": [
                        "mayassar-es-external", 
                        "elasticsearch-mayassar-production", 
                        "Test_nishant"
                    ], 

Here the count is 3, so it creates three instances in both the regions a and b

If you want to traverse output you can use the following method

http://docs.ansible.com/ansible/latest/playbooks_loops.html#looping-over-subelements

这篇关于通过 ansible 创建实例和标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆