如何查看Ansible启动的主机列表

时间:2018-12-25 06:52:10

标签: amazon-web-services amazon-ec2 ansible

我最近盯着Ansible项目工作,并创建了一个项目。该项目使用角色方法来启动EC2,安全组并将ec2添加到主机文件中。

main.yml看起来像下面的类型...

---

- name: Creating Security Group
  local_action:    
     module: ec2_group
     name: "{{ ec2_security_group }}"
     description: The webservers security group
     region: "{{ ec2_region }}"
     aws_access_key: "{{ aws_access_key }}"
     aws_secret_key: "{{ aws_secret_key }}"
     rules:
      - proto: tcp
        from_port: 22
        to_port: 22
        cidr_ip: 0.0.0.0/0
      - proto: tcp
        from_port: 80
        to_port: 80
        cidr_ip: 0.0.0.0/0

      - proto: tcp
        from_port: 8080
        to_port: 8080
        cidr_ip: 0.0.0.0/0
      - proto: tcp
        from_port: 443
        to_port: 443
        cidr_ip: 0.0.0.0/0            
- name: Provision EC2 Box
  local_action:
     module: ec2
     aws_access_key: "{{ aws_access_key }}"
     aws_secret_key: "{{ aws_secret_key }}"
     key_name: "{{ ec2_keypair }}"
     group: "{{ ec2_security_group }}"
     instance_type: "{{ ec2_instance_type }}"
     image: "{{ ec2_image }}"
     vpc_subnet_id: "{{ ec2_subnet_ids }}"
     region: "{{ ec2_region }}"
     instance_tags: '{"Name":"{{ec2_tag_Name}}","Type":"{{ec2_tag_Type}}","Environment":"{{ec2_tag_Environment}}"}'
     assign_public_ip: yes
     wait: true
     count: 1
     volumes: 
     - device_name: /dev/sda1
       device_type: gp2
       volume_size: "{{ ec2_volume_size }}"
       delete_on_termination: true
  register: ec2
- name: Add instance in host file
  add_host:
   name: "{{item.public_ip}}"
   groups: demoserver
  with_items: "{{ ec2.instances }}"

我验证了他的yml文件,它工作正常。现在,如果我在此文件中看到add_host文件属性,它会将最近启动的ec2注册到主机文件中。 使用此文件,我启动了5个ec2实例,现在我想使用ansible命令查看它们。

有人可以帮忙吗,如何查看所有启动的ec2实例。 请告诉您,在此之前,我使用Ansible安装了另一个ec2实例,它正在执行所有任务,并且现在主机文件中有条目。

任何帮助将不胜感激。

0 个答案:

没有答案