-
Notifications
You must be signed in to change notification settings - Fork 1
/
tower_node.yml
84 lines (74 loc) · 2.51 KB
/
tower_node.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
---
- name: Single purpose EC2 playbook - Deploys a RHEL 8 cloud image on EC2 in preparation for Tower
hosts: localhost
gather_facts: False
vars:
instance_count: 1
instance_tag: ''
# Define these variables either in this playbook or via the Twoer survey feature.
#security_group: ''
#subnet_id: ''
#ssh_key_name: ''
#instance_size: ''
#ami_name: ''
tasks:
# https://aws.amazon.com/ec2/instance-types/
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html
- name: Create RHEL instance in ec2
ec2:
image: "{{ ec2_image }}"
instance_type: "{{ ec2_instance_type }}"
aws_access_key: "{{ ec2_access_key }}"
aws_secret_key: "{{ ec2_secret_key }}"
key_name: "{{ ec2_keypair }}"
region: "{{ ec2_region }}"
wait: yes
count: "{{ instance_count|int }}"
instance_tags: "{'ansible_group':'{{ instance_tag }}', 'type':'{{ ec2_instance_type }}', 'group':'{{ ec2_security_group }}', 'Name':'TowerDemo_''{{ tower_user_name }}-node'}"
vpc_subnet_id: "{{ ec2_subnet_id }}"
assign_public_ip: yes
group_id: "{{ ec2_security_group }}"
register: ec2
tags: create
- name: grab EC2 facts
ec2_instance_info:
region: "{{ ec2_region }}"
filters:
instance-state-name: running
"tag:TowerDemo": "{{tower_user_name}}-node"
register: tower_node_facts
- name: add hosts to groups (ANSIBLE RHEL MODE)
add_host:
name: "{{ item.tags.Name }}"
username: "{{ item.tags.Student }}"
short_name: "{{ item.tags.short_name }}"
ansible_host: "{{ item.public_ip_address }}"
ansible_user: "{{ item.tags.username }}"
ansible_port: "{{ ssh_port }}"
ansible_ssh_private_key_file: "{{ playbook_dir }}/{{ec2_name_prefix}}/{{ec2_name_prefix}}-private.pem"
groups: lab_hosts,managed_nodes
with_items:
- "{{ tower_node_facts.instances }}"
changed_when: false
- name: Wait for SSH to come up
wait_for:
host: "{{ item.public_dns_name }}"
port: 22
delay: 60
timeout: 320
state: started
with_items: "{{ ec2.instances }}"
tags: create
#debug: msg="{{ item.public_dns_name }} {{ item.public_ip }} {{ item.private_ip}}"
- name: Display enumerated list
debug: msg="IP is {{ item }}"
with_items: "{{ ec2.instances|map(attribute='public_ip')|list }}"
tags:
- create
- name: CONFIGURE CONTROL NODE
hosts: control_nodes
gather_facts: yes
become: yes
roles:
- control_node
tags: control_node