-
Notifications
You must be signed in to change notification settings - Fork 0
/
AWS-EC2-01.yml
58 lines (47 loc) · 2.05 KB
/
AWS-EC2-01.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
---
- name: boot server
hosts: localhost
gather_facts: false
# Íàø ìîäóëü ec2 ñîçäà¸ò íåêóþ íîâóþ âèðòóàëüíóþ ìàøèíó ïðè êàæäîì ñâî¸ì çàïóñêå, ïîêà âû íå óñòàíîâèòå ñâîé ïàðàìåòð exact_count ñîâìåñòíî ñ ïàðàìåòðîì count_tags (óïîìÿíóòûé â ñòðîêå instance_tags íàáîð ïàðàìåòðîâ).
# Çíà÷åíèå ïîëÿ user_data ìîæåò ïðèìåíÿòüñÿ äëÿ îòïðàâêè ñöåíàðèåâ âûïîëíåíèÿ ïîñëå ñîçäàíèÿ â ñâîþ íîâóþ ÂÌ; ýòî íåâåðîÿòíî ïîëåçíî â ñëó÷àå êîãäà ïåðâîíà÷àëüíàÿ êîíôèãóðàöèÿ òðåáóåòñÿ íåìåäëåííî, ïðåäîñòàâëÿÿ ñåáå êîìàíäû raw.  äàííîì ñëó÷àå ìû ïðèìåíÿåì åãî äëÿ óñòàíîâêè ïðåäâàðèòåëüíûõ òðåáîâàíèé Python ñ öåëüþ ïîñëåäóþùåé èíñòàëëÿöèè ImageMagick.
# ANSIBLE_HOST_KEY_CHECKING=False
# --private-key mastery-key.pem
- name: boot the server
ec2:
access_key: XXXXXXXXXXXXXXXXX
secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
keypair: mastery-key
group: default
type: t2.medium
image: "ami-000848c4d7224c557"
region: eu-west-2
instance_tags: "{'ansible_group':'mastery_server', 'Name':'mastery1'}"
exact_count: 1
count_tag:
ansible_group: "mastery_server"
wait: true
user_data: |
#!/bin/bash
sudo dnf install -y python python2-dnf
register: newserver
# Ïðèâîäèìûé ìîäóëü ec2 òðåáóåò óñòàíîâëåííîé â ñâî¸ì õîñòå Ansible áèáëèîòåêè boto; ìåòîäû äëÿ ýòîãî áóäóò îòëè÷àòüñÿ äëÿ îïåðàöèîííûõ ñèñòåì,
# îäíàêî â íàøåì äåìîíñòðàöèîííîì õîñòå CentOS7 îíà áûëà óñòàíîâëåíà êîìàíäîé sudo yum install python-boto.
- name: show floating ip
debug:
var: newserver.tagged_instances[0].public_ip
- name: Wait for SSH to come up
wait_for_connection:
timeout: 320
- name: add new server
add_host:
name: "mastery1"
ansible_ssh_host: "{{ newserver.tagged_instances[0].public_ip }}"
ansible_ssh_user: "fedora"
- name: configure server
hosts: mastery1
gather_facts: false
tasks:
- name: install imagemagick
dnf:
name: "ImageMagick"
become: "yes"