Browse Source

my aws test environment

master
Markus Bergholz 1 year ago
parent
commit
0ed2a54f4b
1 changed files with 124 additions and 5 deletions
  1. +124
    -5
      ansible/aws.yml

ansible/glusterfs.yml → ansible/aws.yml View File

@@ -12,24 +12,66 @@

vars:
region: eu-west-1
VPC: vpc-c732c7a3

tasks:
- name: rules for my aws security group
ec2_group:
name: myaws
description: allow incomming traffic only from hetzner.osuv.de
region: "{{ region }}"
state: present
vpc_id: "{{ VPC }}"
rules:
- proto: all
rule_desc: hetzner.osuv.de
cidr_ip: "{{ lookup('dig', 'hetzner.osuv.de') }}/32"
- proto: all
rule_desc: internal traffic
cidr_ip: "172.0.0.0/8"
tags:
Name: myaws

- name: add workstation
ec2:
region: "{{ region }}"
keypair: myaws
group: myaws
instance_type: t3a.small
image: ami-0035184034468cd86 # fedora 30
wait: yes
vpc_subnet_id: subnet-41d30025 # eu-west-1c
assign_public_ip: yes
count: 1
instance_tags:
Name: ws
register: ws

- name: create 3 spot instances
ec2:
region: "{{ region }}"
spot_price: 0.0031
spot_price: 0.0036
spot_wait_timeout: 60
keypair: myaws
group_id: sg-85915fe2 # default
group: myaws
instance_type: t3a.micro
image: ami-0035184034468cd86 # fedora 30
wait: yes
vpc_subnet_id: subnet-41d30025 # eu-west-1c
assign_public_ip: yes
count: 3
instance_tags:
Name: spot
register: ec2

- name: Wait for SSH to come up
- name: Wait for ws SSH to come up
wait_for:
host: "{{ item.public_ip }}"
port: 22
state: started
with_items: "{{ ws.instances }}"

- name: Wait for spot SSH to come up
wait_for:
host: "{{ item.public_ip }}"
port: 22
@@ -42,7 +84,13 @@
groupname: launched
with_items: "{{ ec2.instances }}"

- name: add one instance to the seed host group
- name: add ws instances to launched host group
add_host:
hostname: "{{ item.public_ip }}"
groupname: ws
with_items: "{{ ws.instances }}"

- name: add one spot instance to the seed host group
add_host:
hostname: "{{ ec2.instances[0].public_ip }}"
groupname: seed
@@ -56,10 +104,16 @@
ec2_vol:
region: "{{ region }}"
instance: "{{ item.id }}"
volume_size: 1
volume_size: 5
device_name: /dev/sdf
with_items: "{{ ec2.instances }}"

############
#
# configure all
# spot instances
#
############
- name: Configure all instances
hosts: launched
become: True
@@ -100,6 +154,11 @@
path: /mnt/vol1
state: directory

#############
#
# configure one
# spot instance as seed
#############
- name: setup gluster cluster
hosts: seed
become: True
@@ -132,6 +191,66 @@
gluster_volume:
state: started
name: test1

#############
#
# configure ws
#############
- name: setup ws
hosts: ws
become: True
user: fedora
gather_facts: False

tasks:
- name: bootstrap ansible usage by checking availabilty of python
raw: test -e /usr/bin/python || (ln -s /usr/bin/python3 /usr/bin/python)

- name: install packages
become: True
yum:
name: "{{ packages }}"
state: installed
vars:
packages:
- htop
- nano
- nmap
- screen
- git
- lsof
- docker
- ncdu

- name: install python packages
become: True
pip:
name: "{{ packages }}"
executable: pip-3.7
vars:
packages:
- ansible
- boto3
- boto
- awslogs
- mycli
- docker-py

- name: create directory for code-server
file:
path: /home/fedora/code-server
state: directory

- name: Download code server
unarchive:
src: https://github.com/cdr/code-server/releases/download/1.939-vsc1.33.1/code-server1.939-vsc1.33.1-linux-x64.tar.gz
dest: /home/fedora/code-server
remote_src: yes
# - name: apply code-server start on reboot
# cron:
# name: "apply code-server start on reboot"
# special_time: reboot
# job: "cd /home/fedora/code-server/code-server1.939-vsc1.33.1-linux-x64; nohup ./code-server /home/fedora/ --password=password </dev/null >/dev/null 2>&1 &"
# mount -t glusterfs 172.31.4.217:/test1 /oi

# Shrink and increase

Loading…
Cancel
Save