Skip to content
Snippets Groups Projects
Commit 7793ffc4 authored by jurgenhaas's avatar jurgenhaas
Browse files

AWS provisioning

parent 77a4cf8c
No related branches found
No related tags found
No related merge requests found
##
# Dummy Ansible playbook
---
# file: cloud.yml
- name: "No cloud action required"
hosts: "localhost"
connection: local
gather_facts: false
sudo: no
tasks: []
ec2.yml 0 → 100644
##
# Ansible playbook for managing an ec2 inventory
---
# file: ec2.yml
- name: "EC2: Launch a new host"
hosts: "localhost"
connection: local
gather_facts: false
sudo: no
tasks:
- name: "Create the new instance"
ec2:
instance_tags: '{"Name":"Ansible-Host-{{ host }}","AnsibleHost":"{{ host }}","AnsibleGroups":"{{ initgroups }}"}'
assign_public_ip: yes
group_id: "{{ ec2_group_id }}"
key_name: "{{ ec2_key_name }}"
image: "{{ ec2_ami_id }}"
instance_type: "{{ ec2_instance_type }}"
vpc_subnet_id: "{{ ec2_subnet_id }}"
region: "{{ ec2_region }}"
state: present
wait: yes
register: ec2
- name: "Waiting for the new instance(s) to get up and running"
ec2:
instance_ids: "{{ ec2.instance_ids }}"
instance_type: "{{ ec2_instance_type }}"
region: "{{ ec2_region }}"
state: running
wait: yes
- name: "Add new instance(s) to the inventory"
add_host:
hostname="{{ host }}"
static_ipv4="{{ item.public_ip }}"
groups="{{ initgroups }}"
with_items: ec2.instances
- name: "Waiting for SSH service becoming available"
wait_for:
host="{{ item.public_ip }}"
port=22
delay=10
timeout=120
state=present
with_items: ec2.instances
......@@ -5,14 +5,16 @@ cd $( cd $(dirname $(realpath $0)) ; pwd )
if [ "$2" == "" ]
then
echo "Usage"
echo "inithost.sh HOST IP [USER [KEYFILE]]"
echo "inithost.sh HOST IP [USER [KEYFILE [GROUPS]]]"
exit 101;
fi
CLOUD=cloud
HOST=$1
IP=$2
IP=inithostip=$2
ROOT=root
KEYFILE=--ask-pass
INITGROUPS=inventory
shift
shift
if [ "$1" != "" ]
......@@ -25,6 +27,16 @@ if [ "$1" != "" ]
KEYFILE=--private-key=$1
shift
fi
if [ "$1" != "" ]
then
INITGROUPS=$1
shift
fi
if [ "$IP" == "inithostip=ec2" ]
then
CLOUD=ec2
IP=
fi
./ansible-playbook.sh inithost --extra-vars="inituser=$ROOT host=$HOST inithostip=$IP firstuser=$USER" --tags="prepare" $KEYFILE "$@"
./ansible-playbook.sh inithost --extra-vars="host=$HOST inithostip=$IP distribute_keys=true" --tags="config" "$@"
./ansible-playbook.sh inithost --extra-vars="cloud=$CLOUD host=$HOST inituser=$ROOT firstuser=$USER initgroups=$INITGROUPS $IP distribute_keys=true" $KEYFILE "$@"
......@@ -4,21 +4,22 @@
---
# file: inithost.yml
# Check if we need to launch an instance there first
- include: "{{ cloud }}.yml"
- name: "Prepare 1"
hosts: "{{ host }}"
connection: local
gather_facts: false
sudo: no
tags:
- prepare
tasks:
- name: "InitHost | Remove previous entries from known_hosts"
shell: "ssh-keygen -R {{ item }}"
with_items:
- '{{ inithostip }}'
- '{{ inithostip|default(static_ipv4) }}'
- '{{ host }}'
- name: "InitHost | Copy root id to new host"
shell: "ssh-copy-id -i root@{{ inithostip }} -o PasswordAuthentication=yes -o PubkeyAuthentication=no -o IdentitiesOnly=yes"
shell: "ssh-copy-id -i root@{{ inithostip|default(static_ipv4) }} -o PasswordAuthentication=yes -o PubkeyAuthentication=no -o IdentitiesOnly=yes"
register: inithost_ssh_copy_id
changed_when: "inithost_ssh_copy_id.rc != 0"
failed_when: false
......@@ -28,22 +29,18 @@
connection: local
gather_facts: false
sudo: yes
tags:
- prepare
tasks:
- name: "InitHost | Include new host into /etc/hosts"
lineinfile:
dest=/etc/hosts
regexp="^{{ inithostip }} "
line="{{ inithostip }} {{ host }}"
regexp="^{{ inithostip|default(static_ipv4) }} "
line="{{ inithostip|default(static_ipv4) }} {{ host }}"
- name: "Setup first user"
hosts: "{{ host }}"
gather_facts: false
user: "{{ inituser }}"
sudo: yes
tags:
- prepare
vars:
first_user:
- name: "{{ firstuser }}"
......@@ -65,25 +62,17 @@
user={{ item.name }}
key="{{ lookup('file', inventory_dir + '/files/keys/' + item.name + '.d2s.pub') }}"
with_items: first_user
# TODO: Move the following to common role and make it conditional
#- name: "InitHost | Remove console-kit-daemon"
# shell: mv console-kit-daemon console-kit-daemon.off chdir=/usr/sbin
# ignore_errors: true
- name: "Security setup"
hosts: "{{ host }}"
gather_facts: true
sudo: yes
tags:
- config
roles:
- common
- name: "Upload keys"
hosts: "all"
sudo: yes
tags:
- config
roles:
- { role: common, when: ignore_these_tasks is defined }
- { role: commonauth }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment