Getting a handle of ec2-instances

26 views
Skip to first unread message

Yasser Hussain

unread,
Jun 10, 2015, 8:37:23 AM6/10/15
to ansible...@googlegroups.com
I have provisioned an amazon instance using ec2 module. Now I need to do some more manipulation on the instance. So does ansible get a handle on the instance it just created? 

benno joy

unread,
Jun 10, 2015, 10:54:51 AM6/10/15
to ansible...@googlegroups.com

On Wed, Jun 10, 2015 at 12:38 PM, Yasser Hussain <yasserhu...@gmail.com> wrote:
I have provisioned an amazon instance using ec2 module. Now I need to do some more manipulation on the instance. So does ansible get a handle on the instance it just created? 

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f729cb81-8c6a-4c05-b8c7-97239fe22104%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brian Coca

unread,
Jun 10, 2015, 10:54:53 AM6/10/15
to ansible...@googlegroups.com
You should be able to register a var which will get return info from
the module, I believe this includes new instance ids.
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/f729cb81-8c6a-4c05-b8c7-97239fe22104%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Brian Coca

sirkubax

unread,
Jun 11, 2015, 8:19:34 AM6/11/15
to ansible...@googlegroups.com
A quick example


- hosts: localhost
  connection: local
  gather_facts: False

  tasks:

    - name: Provision a set of instances
      ec2:
          region: eu-central-1
          key_name: some_aws_key
          group: default
          instance_type: t2.micro
          image: ami-accff2b1
          vpc_subnet_id: subnet-xxxxxxx
          wait: yes
          exact_count: 3
          count_tag:
             Name: Demo
          instance_tags:
             Name: Demo
             test_tag: Demo
      register: ec2_ip: yes

i    - debug: var=ec2

    - name: Add instances to host group
      local_action: add_host hostname={{ item.public_ip }} groupname=my_group
      with_items: ec2.instances
    - name: Add tag to instances
      local_action: ec2_tag resource={{ item.id }} region=eu-central-1 state=present
      with_items: ec2.instances
      args:
        tags:
          Name: EP2

    - name: Add tag to instances
      local_action: ec2_tag resource={{ item.id }} region=eu-central-1 state=present
      with_items: ec2.instances
      args:
        tags:
          Name: EP2




W dniu środa, 10 czerwca 2015 16:54:53 UTC+2 użytkownik Brian Coca napisał:
You should be able to register a var which will g
    - name: Add tag to instances
      local_action: ec2_tag resource={{ item.id }} region=eu-central-1 state=present
      with_items: ec2.instances
      args:
        tags:
          Name: EP2
Reply all
Reply to author
Forward
0 new messages