Skip to content

Instantly share code, notes, and snippets.

@SharkWipf
Created March 23, 2019 03:34
Show Gist options
  • Save SharkWipf/b1237e7d39a7a28bb2455007df31dc64 to your computer and use it in GitHub Desktop.
Save SharkWipf/b1237e7d39a7a28bb2455007df31dc64 to your computer and use it in GitHub Desktop.
Ansible skeleton project helper functions
# Ansible helper functions
# Source this file with Bash to load the functions (or put it in your .bashrc)
# Create a skeleton for a new role
ansible-skeleton-role() {
if [ "$1" = '' ]; then role="common"; else role="$1"; fi
mkdir -p "${role}"/{tasks,handlers,templates,files,vars,defaults,meta,library,module_utils,lookup_plugins}
}
# Create a new project skeleton
ansible-skeleton() {
if [ "$1" = '' ]; then role="common"; else role="$1"; fi
mkdir -p {group,host}_vars library module_utils filter_plugins roles
( cd roles; ansible-skeleton-role "$role" )
touch production staging {group,host}_vars/.gitkeep site.yml;
tree -a
}
# Create a new project skeleton, alternate version
ansible-skeleton-alt() {
if [ "$1" = '' ]; then role="common"; else role="$1"; fi
mkdir -p inventories/{production,staging}/{group,host}_vars library module_utils filter_plugins roles
( cd roles; ansible-skeleton-role "$role" )
touch inventories/{production,staging}/{{group,host}_vars/.gitkeep,hosts} site.yml;
tree -a
}
# Remove all empty directories recursively, thus leaving only the folders you actually used
ansible-skeleton-cleanup() {
find . ! -path . -type d -print0 | xargs -0 rmdir --ignore-fail-on-non-empty
tree -a
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment