This repository has been archived by the owner on Oct 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-ami.yml
86 lines (71 loc) · 2.23 KB
/
build-ami.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
85
86
---
- import_playbook: instance.yml instance_state=present
- name: wait for instance
hosts: localhost
connection: local
gather_facts: no
tasks:
- name: write instance id to file
local_action: copy content="{{ item.id }}" dest="/ansible/{{ instance_id_filename }}"
with_items: "{{ ec2.instances }}"
- name: Add new instance to coreos group
add_host:
hostname: "{{ item.public_ip }}"
groupname: coreos
with_items: "{{ ec2.instances }}"
- name: Wait for instance
local_action:
wait_for port=22 host='{{ item.public_ip }}' search_regex=OpenSSH
with_items: "{{ ec2.instances }}"
- name: Prepare instance with ansible
hosts: coreos
gather_facts: no
roles:
- defunctzombie.coreos-bootstrap
tasks:
- name: install docker-py
pip:
name: docker-py
executable: /home/core/bin/pip
- name: Prepare Conjur
hosts: coreos
roles:
- conjur
- name: Create image
hosts: coreos
vars:
terminate_after_create: yes
ami_name: "cyberark-conjur-{{ conjur_version }}-{{ ansible_date_time.epoch }}"
tasks:
- ec2_metadata_facts:
- name: Remove all authorized keys
shell: rm -vrf /home/core/.ssh/authorized_key*
args:
warn: no # file module doesn't support wildcards
- name: AMI creation
connection: local
vars:
ansible_python_interpreter: /usr/bin/python
ec2_ami:
instance_id: "{{ ansible_ec2_instance_id }}"
wait: yes
name: "{{ ami_name }}"
tags:
Name: "cyberark-conjur"
Version: "{{ conjur_version }}"
Created: "{{ ansible_date_time.epoch }}"
launch_permissions:
group_names: ['all']
register: ami
- name: write AMI id
local_action: copy content="{{ ami.image_id}}" dest="/ansible/{{ ami_id_filename }}"
- name: write AMI with region to vars file
local_action: copy content="us-east-1{{ ':' }} {{ ami.image_id}}" dest="/ansible/vars/us-east-1.yml"
- name: terminate instance
connection: local
vars:
ansible_python_interpreter: /usr/bin/python
ec2:
instance_id: "{{ ansible_ec2_instance_id }}"
state: absent
when: terminate_after_create