-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-ec2-CentOS-8.yml
69 lines (61 loc) · 1.89 KB
/
create-ec2-CentOS-8.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
---
# ansible-playbook create-ec2-CentOS.yml -vv
# Play 1: Create instance on AWS
- name: Create EC2 instance
hosts: localhost
connection: local
become: false
gather_facts: true
vars:
- ec2_instance_type: t2.micro
# https://wiki.centos.org/Cloud/AWS#Images
- ec2_ami_id: ami-01ca03df4a6012157
- ec2_name_tag: nleiva-centos-8
- ec2_username: centos
- ec2_ansible_group_tag: Centos
- volume:
- device_name: /dev/sda1
volume_type: gp2
volume_size: 30
delete_on_termination: true
tasks:
- name: Create CentOS EC2 instance in AWS
include_role:
name: aws_create_ec2
- name: Grab facts for the instance(s) we just created
ec2_instance_info:
region: "{{ ec2_region }}"
filters:
instance-state-name: running
"tag:Name": "{{ ec2_name_tag }}"
register: ansible_node_facts
- name: Set facts for next play
set_fact:
instance_name: "{{ ec2_name_tag }}"
- name: Add instance(s) to my_instances group
add_host:
name: "{{ item.tags.Name }}"
ansible_host: "{{ item.public_ip_address }}"
ansible_user: "{{ ec2_username }}"
private_ip: "{{ item.private_ip_address }}"
groups:
- my_instances
with_items: "{{ ansible_node_facts.instances }}"
# Play 2: Install packages
- name: Configure Instance(s)
hosts: "my_instances"
become: true
gather_facts: true
vars_files:
- ./vars/go_install.yml
- ./vars/go_vs_code.yml
vars:
- epel_repo: epel-release
- user: centos
tasks:
- name: Display variables/facts known for instance
ansible.builtin.debug:
msg: "Running {{ ansible_distribution }} {{ ansible_distribution_version }} ({{ ansible_os_family }}), IP address: {{ ansible_host }}"
- name: Install packages and config files
include_role:
name: configure_instance