Creating and Naming a Cluster of EC2 Servers Using Ansible

105 views
Skip to first unread message

Navid Paya

unread,
Dec 29, 2014, 11:09:03 AM12/29/14
to ansible...@googlegroups.com
Hi
I'm trying to automate creating and destroying our staging environment. So far, I have a playbook to create the cluster:

---
- name: Launch an EC2 instance from our our latest AMI in staging
  hosts: localhost
  connection: local
  gather_facts: no
  tasks:
  - name: Start the new EC2 instance
    ec2:
      image:  ami-xxxxxxxx
      region: ap-southeast-1
      zone:   ap-southeast-1b
      instance_type: m3.medium
      vpc_subnet_id: subnet-xxxxxxxx
      group_id: ['sg-xxxxxxxx', 'sg-xxxxxxxx']
      key_name: blahblah-deploy
      instance_tags:
        Cluster:  grabqa01
        Name:     "{{ item}}.grabqa01.net"
        Env:      staging
        Role:     "{{ item }}"
    with_items:
      - redis
      - postgresql
      - frontend
      - dispatcher-athena
      - dispatcher-hermes
      - dispatcher-listener
      - dispatcher-processor
      - poi

Now since EC2 instances take forever to initialize, I give it 20 minutes and then run another playbook to create DNS records for the created instances using Route53. I wanted to do this which would be so nice if it worked:

- name: Set DNS Records
  hosts: 'tag_Cluster_grabqa01:&tag_Role_{{ item }}'
  tasks:
  - route53:
      aws_access_key: xxxxxxxxxxxxxxx
      aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
      command: create
      zone: grabqa01.net
      record: {{ item }}.grabqa01.net
      type: A
      ttl: 600
      value: "{{ ansible_all_ipv4_addresses }}"
    delegate_to: localhost
  with_items:
    - redis
    - postgresql
    - frontend
    - dispatcher-athena
    - dispatcher-hermes
    - dispatcher-listener
    - dispatcher-processor
    - poi

Basically, I want to find the hosts matching a search and then create a DNS record pointing at them. What would be the best way to do that? I'd rather not have to write a block for every single role I have.

Dan Vaida

unread,
Jan 10, 2015, 8:26:57 AM1/10/15
to ansible...@googlegroups.com
I'm doing this by registering the results of the ec2 provisioning task and then cycle through the hosts in a subsequent task for creating the dns records.

Navid Paya

unread,
Jan 10, 2015, 8:55:42 AM1/10/15
to ansible...@googlegroups.com
Thanks for the reply, Dan. Do you have the code available somewhere?

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/2QFD21LVCkw/unsubscribe.
To unsubscribe from this group and all its topics, 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/6cb9be9e-41a0-47b7-9568-45d2794c7a06%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Dan Vaida

unread,
Jan 10, 2015, 9:40:36 AM1/10/15
to ansible...@googlegroups.com
On the run now but will share this later.

Btw, are you really missing the task of allocating the EIPs to the instances? This would go before the route53 task.

Dan.
--

Dan Vaida

unread,
Jan 10, 2015, 9:55:03 AM1/10/15
to ansible...@googlegroups.com
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

Navid Paya

unread,
Jan 10, 2015, 11:14:14 PM1/10/15
to ansible...@googlegroups.com
Thanks a bunch, Dan. That is helpful. My instances are all VPC instances and I use ELB for all of them so just the private IP works fine for it.

To unsubscribe from this group and all its topics, 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/24cf4a0d-007c-4feb-997e-5a6cbef6dcc5%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages