Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Ansible Framework Container
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ansible
Playbooks
Ansible Framework Container
Commits
7793ffc4
Commit
7793ffc4
authored
9 years ago
by
jurgenhaas
Browse files
Options
Downloads
Patches
Plain Diff
AWS provisioning
parent
77a4cf8c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
cloud.yml
+12
-0
12 additions, 0 deletions
cloud.yml
ec2.yml
+46
-0
46 additions, 0 deletions
ec2.yml
inithost.sh
+16
-4
16 additions, 4 deletions
inithost.sh
inithost.yml
+7
-18
7 additions, 18 deletions
inithost.yml
with
81 additions
and
22 deletions
cloud.yml
0 → 100644
+
12
−
0
View file @
7793ffc4
##
# Dummy Ansible playbook
---
# file: cloud.yml
-
name
:
"
No
cloud
action
required"
hosts
:
"
localhost"
connection
:
local
gather_facts
:
false
sudo
:
no
tasks
:
[]
This diff is collapsed.
Click to expand it.
ec2.yml
0 → 100644
+
46
−
0
View file @
7793ffc4
##
# 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
This diff is collapsed.
Click to expand it.
inithost.sh
+
16
−
4
View file @
7793ffc4
...
...
@@ -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
"
$@
"
This diff is collapsed.
Click to expand it.
inithost.yml
+
7
−
18
View file @
7793ffc4
...
...
@@ -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
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment