Compare commits
10 commits
56cae79813
...
1bf9fc95ab
Author | SHA1 | Date | |
---|---|---|---|
1bf9fc95ab | |||
88f7f7ed55 | |||
d1f0aa8848 | |||
6526d7bf2b | |||
1a6356a44a | |||
a34df88a5d | |||
0912b451f2 | |||
8e171bb79d | |||
8dc583b44e | |||
251f879b1b |
6 changed files with 171 additions and 1 deletions
10
README.md
10
README.md
|
@ -1 +1,9 @@
|
||||||
This repository is used to build playbooks based on files that contain role name and version number.
|
This repository is used to build playbooks based on files that contain role name and version number.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
First, define a branch to use in /ansible/branch.
|
||||||
|
Next, download just the file build_ansible.sh with the following command:
|
||||||
|
```curl -k "https://git.actcur.com/actcur-ansible/playbook-builder/raw/branch/prod/build_ansible.sh" -H "accept: application/raw" -o /ansible/build_ansible.sh```
|
||||||
|
Note: the prod version of this script can be used. If there is a branch mismatch, this script will download the correct version and restart
|
||||||
|
Finally, run build_ansible.sh
|
128
build_ansible.sh
Normal file
128
build_ansible.sh
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# ensure we are running the latest version of the script from the correct branch
|
||||||
|
if [ -f /ansible/branch ];
|
||||||
|
then
|
||||||
|
branch=`cat /ansible/branch`
|
||||||
|
else
|
||||||
|
branch="prod"
|
||||||
|
fi
|
||||||
|
|
||||||
|
#determine if we need to download the latest version
|
||||||
|
regrab=false
|
||||||
|
if [ -f /ansible/current ]; then
|
||||||
|
latest=`cat /ansible/current`
|
||||||
|
echo $latest
|
||||||
|
l_branch=`echo "$latest" | grep -Po ".+:" | grep -Po "[^:]+"`
|
||||||
|
l_time=`echo "$latest" | grep -Po ":.+" | grep -Po "[^:]+"`
|
||||||
|
if [ ! "$l_branch" = "$branch" ]; then
|
||||||
|
regrab=true
|
||||||
|
else
|
||||||
|
c_time=`date +%s`
|
||||||
|
if [[ `expr $c_time - $l_time` -gt 120 ]]; then
|
||||||
|
regrab=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
regrab=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
if $regrab;then
|
||||||
|
# download latest version
|
||||||
|
curl -k "https://git.actcur.com/actcur-ansible/playbook-builder/raw/branch/$branch/build_ansible.sh" -H "accept: application/raw" -o /tmp/build_ansible.sh
|
||||||
|
|
||||||
|
# verify that download was sucessful
|
||||||
|
count=`grep -P "(#!/bin/bash)|(end of build_ansible.sh)" /tmp/build_ansible.sh | wc -l`
|
||||||
|
if [ "$count" != "3" ];then
|
||||||
|
echo "failed to grab latest build_ansible.sh file, exiting"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
# update build_ansible file and update branch/timestamp info in current
|
||||||
|
cp /tmp/build_ansible.sh /ansible/build_ansible.sh
|
||||||
|
echo ${branch}:`date +%s` > /ansible/current
|
||||||
|
|
||||||
|
# verify the parent script is not build_ansible.sh (to prevent the possibility of recurring until the system crashes in the case of an issue)
|
||||||
|
me=$(basename "$0")
|
||||||
|
parent=$(ps -o args= $PPID)
|
||||||
|
if [[ "$parent" != *"$me"* ]];then
|
||||||
|
/bin/bash /ansible/build_ansible.sh
|
||||||
|
fi
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
fqdn=`hostnamectl hostname`
|
||||||
|
curl -k "https://git.actcur.com/actcur-ansible/playbook-builder/raw/branch/$branch/playbook_templates/$fqdn" -H "accept: application/raw" -o /tmp/$fqdn
|
||||||
|
|
||||||
|
# verify file was downloaded successfully
|
||||||
|
count=`grep -P "end of file" /tmp/$fqdn | wc -l`
|
||||||
|
if [ "$count" != "1" ];then
|
||||||
|
echo "failed to grab current playbook build file for $fqdn, exiting"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
# build playbook, retrieve roles and add variables to roles
|
||||||
|
mkdir -p /ansible/roles/
|
||||||
|
mkdir -p /ansible/new/roles
|
||||||
|
mkdir -p /ansible/prev/roles
|
||||||
|
# delete roles from previous attempt to update them
|
||||||
|
rm -r /ansible/new/roles/*
|
||||||
|
|
||||||
|
# create base playbook
|
||||||
|
echo "- hosts: localhost
|
||||||
|
become: true
|
||||||
|
|
||||||
|
roles:" > /ansible/new/$fqdn.yml
|
||||||
|
|
||||||
|
while read line
|
||||||
|
do
|
||||||
|
elements=()
|
||||||
|
for e in $(echo $line | tr ":" "\n"); do elements+=("$e");done
|
||||||
|
case ${elements[0]} in
|
||||||
|
"role")
|
||||||
|
# format role:role name:branch/tag to use
|
||||||
|
# clone role repo from specific tag/branch w/o history
|
||||||
|
git clone -b ${elements[2]} --depth 1 https://git.actcur.com/actcur-ansible/role-${elements[1]}.git /ansible/new/roles/${elements[1]}
|
||||||
|
|
||||||
|
# verify branch was cloned successfully
|
||||||
|
count=`ls /ansible/new/roles/${elements[1]}/ | wc -l`
|
||||||
|
if [[ $count -lt 5 ]];then
|
||||||
|
echo "issue grabbing role $role - dir/file count less than 9, exiting"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
#get tags and add role
|
||||||
|
if [ -n "${elements[3]}" ];then
|
||||||
|
tags="\"${elements[3]//,/\",\"}\""
|
||||||
|
echo " - { role: ${elements[1]}, tags: [${tags}] }" >> /ansible/new/$fqdn.yml
|
||||||
|
else
|
||||||
|
echo " - ${elements[1]}" >> /ansible/new/$fqdn.yml
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# retrieve var file if it exists
|
||||||
|
curl -k "https://git.actcur.com/actcur-ansible/playbook-builder/raw/branch/$branch/var_files/${elements[1]}/$fqdn" -H "accept: application/raw" -o /tmp/main.yml
|
||||||
|
# /ansible/new/roles/${elements[1]}/vars/main.yml
|
||||||
|
# verifty file was downloaded successfully
|
||||||
|
count=`grep -P "(---)|(end of file)" /tmp/main.yml | wc -l`
|
||||||
|
if [ "$count" == "2" ];then
|
||||||
|
mv /tmp/main.yml /ansible/new/roles/${elements[1]}/vars/main.yml
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"#*")
|
||||||
|
# this is a comment, ignore it
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "skipping invalid entry in playbook build file for $fqdn"
|
||||||
|
echo "entry: $line"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done </tmp/$fqdn
|
||||||
|
rm -r /ansible/prev/*
|
||||||
|
mv /ansible/$fqdn.yml /ansible/prev/
|
||||||
|
mv /ansible/roles/ /ansible/prev
|
||||||
|
mv /ansible/new/* /ansible/
|
||||||
|
|
||||||
|
cd /ansible
|
||||||
|
ansible-playbook ${fqdn}.yml
|
||||||
|
|
||||||
|
# end of build_ansible.sh
|
7
playbook_templates/privtorrents.actcur.com
Normal file
7
playbook_templates/privtorrents.actcur.com
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
role:core:v1.0:core
|
||||||
|
role:mount:v1.0:core,mount
|
||||||
|
role:deluge:v1.0:workload,deluge
|
||||||
|
role:nginx-ssl:v1.0:common,nginx-ssl
|
||||||
|
role:certbot:v1.0:common,certbot
|
||||||
|
|
||||||
|
# end of file
|
7
var_files/certbot/privtorrents.actcur.com
Normal file
7
var_files/certbot/privtorrents.actcur.com
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
# vars file for certbot on privtorrents.actcur.com
|
||||||
|
|
||||||
|
domains:
|
||||||
|
- domain: privtorrents.actcur.com
|
||||||
|
|
||||||
|
# end of file
|
12
var_files/mount/privtorrents.actcur.com
Normal file
12
var_files/mount/privtorrents.actcur.com
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
---
|
||||||
|
# vars file for mount on privtorrents.actcur.com
|
||||||
|
|
||||||
|
mounts:
|
||||||
|
nfs:
|
||||||
|
- name: deluge
|
||||||
|
host: host.actcur.com
|
||||||
|
remote: /mnt/butter/video/deluge
|
||||||
|
local: /mnt/deluge
|
||||||
|
type: nfs
|
||||||
|
|
||||||
|
# end of file
|
8
var_files/nginx-ssl/privtorrents.actcur.com
Normal file
8
var_files/nginx-ssl/privtorrents.actcur.com
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
# vars file for nginx-ssl on privtorrents.actcur.com
|
||||||
|
|
||||||
|
domains:
|
||||||
|
- domain: privtorrents.actcur.com
|
||||||
|
port: 8112
|
||||||
|
|
||||||
|
# end of file
|
Loading…
Add table
Reference in a new issue