Last active
February 11, 2020 15:10
-
-
Save dohq/994dbf53f124ef83f58d4ffd1a411761 to your computer and use it in GitHub Desktop.
Initialize Ansible Best Prictice DIRs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
IFS=$'\n\t' | |
create () { | |
if [[ $1 == "d" ]]; then | |
if [ ! -d $2 ]; then mkdir $2; echo "make dir $2"; fi | |
elif [[ $1 == "y" ]]; then | |
if [ ! -f $2 ]; then touch $2; echo "---" >> $2; echo "make yaml $2"; fi | |
fi | |
} | |
INVENTORY=("production" "staging" "development") | |
ROLE_DIRS=("tasks" "handlers" "templates" "files" "vars" "defaults") | |
# Dirs | |
create d inventories | |
create d roles | |
create d roles/common | |
for d in ${INVENTORY[@]}; do create d inventories/$d; done | |
for d in ${INVENTORY[@]}; do create d inventories/$d/host_vars; done | |
for d in ${INVENTORY[@]}; do create d inventories/$d/group_vars; done | |
for d in ${ROLE_DIRS[@]}; do create d roles/common/$d; done | |
# Files | |
create y site.yml | |
create y webservers.yml | |
create y databases.yml | |
for d in ${INVENTORY[@]}; do create y inventories/$d/hosts.yml; done | |
for d in ${ROLE_DIRS[@]}; do create y roles/common/$d/main.yml; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment