SHARE
TWEET

Untitled

a guest Sep 11th, 2019 86 in 7 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ---
  2. - name: Create instances
  3.   hosts: localhost
  4.   gather_facts: False
  5.  
  6.   tasks:
  7.     - name: get vars
  8.       include_vars:
  9.         dir: roles/{{ role }}/vars/
  10.  
  11.     - name: Launch instance
  12.       ec2:
  13.          key_name: "{{ keypair }}"
  14.          group_id: "{{ security_group }}"
  15.          instance_type: "{{ instance_type }}"
  16.          image: "{{ image }}"
  17.          count: "{{ number }}"
  18.          wait: true
  19.          region: "{{ region }}"
  20.          vpc_subnet_id: "{{ vpc_subnet }}"
  21.          assign_public_ip: "{{ public }}"
  22.          instance_tags: '{"task":"{{ service }}"}'
  23.          volumes:
  24.            - device_name: /dev/sdb
  25.              volume_type: gp2
  26.              volume_size: 250
  27.              delete_on_termination: false
  28.       register: ec2
  29.  
  30.     - name: Add Name to hosts.
  31.       ec2_tag:
  32.        region: "{{ region }}"
  33.        resource: '{{ item.id }}'
  34.        state: present
  35.        tags:
  36.          Name: '{{ service }}0{{ item.ami_launch_index }}'
  37.       loop: "{{ ec2.instances }}"
  38.  
  39.     - name: Add new instances to host group
  40.       add_host:
  41.         hostname: '{{ service }}0{{ item.ami_launch_index }}'
  42.         groupname: launched
  43.       loop: "{{ ec2.instances }}"
  44.  
  45.     - name: Refresh EC2 inventory
  46.       meta: refresh_inventory
  47.  
  48.     - name: Retrieve tags
  49.       ec2_tag:
  50.         region: '{{ region }}'
  51.         resource: '{{ item.id }}'
  52.         state: list
  53.       register: ec2_tags
  54.       loop: '{{ ec2.instances }}'
  55.  
  56.     - name: Route53
  57.       route53:
  58.         command: create
  59.         private_zone: false
  60.         overwrite: yes
  61.         record: "{{ service }}0{{ item.ami_launch_index }}.{{ domain }}"
  62.         zone: "{{ domain }}
  63.         type: A
  64.         ttl: 60
  65.         value: "{{ item.private_ip }}"
  66.       loop: "{{ ec2.instances }}"
  67.  
  68.     - name: Wait for SSH to come up
  69.       delegate_to: "{{ item.private_ip }}"
  70.       wait_for_connection:
  71.       loop: "{{ ec2.instances }}"
  72.  
  73.   - name: Configure instances
  74.     hosts: '{{ service }}'
  75.     gather_facts: yes
  76.     user: ubuntu
  77.     become: yes
  78.     tasks:
  79.  
  80.     - name: Turn that inventory_hostname into a hostname
  81.       hostname:
  82.         name: '{{ inventory_hostname }}'
  83.  
  84.     - name: Update package lists
  85.       apt:
  86.         update_cache: yes
  87.         upgrade: yes
  88.  
  89.     - name: Add packages
  90.       apt: name={{ item }} state=installed
  91.       with_items:
  92.         - glances
  93.  
  94.     - name: Debug Message
  95.       debug:
  96.         msg: vars
  97.  
  98.     - name: add roles
  99.       user: ubuntu
  100.       become: yes
  101.       hosts: '{{ service }}'
  102.       roles:
  103.         - '{{ role }}'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top