|
4 | 4 | gather_facts: false
|
5 | 5 |
|
6 | 6 | vars:
|
| 7 | + # aws_profile: default |
| 8 | + # TODO |
| 9 | + aws_profile: jeffgeerling |
| 10 | + aws_region: us-east-1 # North Virginia |
| 11 | + aws_ec2_ami: ami-06cf02a98a61f9f5e # CentOS 7 |
| 12 | + |
7 | 13 | instances:
|
8 | 14 | - name: a4d.lamp.varnish
|
9 | 15 | group: "lamp_varnish"
|
|
66 | 72 | ec2_group:
|
67 | 73 | name: "{{ item.name }}"
|
68 | 74 | description: Example EC2 security group for A4D.
|
69 |
| - region: "{{ item.region | default('us-west-2') }}" # Oregon |
70 |
| - state: present |
| 75 | + state: absent |
71 | 76 | rules: "{{ item.rules }}"
|
72 | 77 | rules_egress: "{{ item.rules_egress }}"
|
| 78 | + profile: "{{ aws_profile }}" |
| 79 | + region: "{{ aws_region }}" |
73 | 80 | with_items: "{{ security_groups }}"
|
74 | 81 |
|
75 | 82 | - name: Provision EC2 instances.
|
|
79 | 86 | inventory_group: "{{ item.group | default('') }}"
|
80 | 87 | inventory_host: "{{ item.name | default('') }}"
|
81 | 88 | group: "{{ item.security_group | default('') }}"
|
82 |
| - instance_type: "{{ item.type | default('t2.micro')}}" # Free |
83 |
| - image: "{{ item.image | default('ami-3ecc8f46') }}" # CentOS 7 |
84 |
| - region: "{{ item.region | default('us-west-2') }}" # Oregon |
| 89 | + instance_type: "{{ item.type | default('t2.micro')}}" |
| 90 | + image: "{{ aws_ec2_ami }}" |
85 | 91 | wait: yes
|
86 | 92 | wait_timeout: 500
|
87 | 93 | exact_count: 1
|
88 | 94 | count_tag:
|
89 | 95 | inventory_group: "{{ item.group | default('') }}"
|
90 | 96 | inventory_host: "{{ item.name | default('') }}"
|
| 97 | + profile: "{{ aws_profile }}" |
| 98 | + region: "{{ aws_region }}" |
91 | 99 | register: created_instances
|
92 | 100 | with_items: "{{ instances }}"
|
93 | 101 |
|
|
96 | 104 | name: "{{ item.1.tagged_instances.0.public_ip }}"
|
97 | 105 | groups: "aws,{{ item.1.item.group }},{{ item.1.item.name }}"
|
98 | 106 | # You can dynamically add inventory variables per-host.
|
99 |
| - ansible_user: ec2-user |
| 107 | + ansible_user: centos |
| 108 | + ansible_ssh_private_key_file: ~/.ssh/lamp_aws.pem |
100 | 109 | host_key_checking: false
|
101 | 110 | mysql_replication_role: >-
|
102 | 111 | {{ 'master' if (item.1.item.name == 'a4d.lamp.db.1')
|
|
105 | 114 | when: item.1.instances is defined
|
106 | 115 | with_indexed_items: "{{ created_instances.results }}"
|
107 | 116 |
|
108 |
| -# Run some general configuration on all AWS hosts. |
109 | 117 | - hosts: aws
|
110 | 118 | gather_facts: false
|
111 | 119 |
|
112 | 120 | tasks:
|
113 |
| - - name: Wait for port 22 to become available. |
114 |
| - local_action: "wait_for port=22 host={{ inventory_hostname }}" |
115 |
| - |
116 |
| - - name: Set selinux into 'permissive' mode. |
117 |
| - selinux: policy=targeted state=permissive |
118 |
| - become: yes |
| 121 | + - name: Wait for host to become available. |
| 122 | + wait_for_connection: |
0 commit comments