Skip to content

Instantly share code, notes, and snippets.

@justdoit0823
Created October 4, 2017 08:17
Show Gist options
  • Save justdoit0823/08c8212f78280d537fb32141d95f1925 to your computer and use it in GitHub Desktop.
Save justdoit0823/08c8212f78280d537fb32141d95f1925 to your computer and use it in GitHub Desktop.
A playbook to create project directory layout based on the best practices.
- hosts: localhost
vars:
dprefix: ~/playbook/
role_prefix: "{{dprefix}}roles/"
env_files:
- "{{dprefix}}production"
- "{{dprefix}}staging"
var_dirs:
- "{{dprefix}}group_vars/"
- "{{dprefix}}host_vars/"
playbook_files:
- "{{dprefix}}site.yml"
- "{{dprefix}}webservers.yml"
- "{{dprefix}}dbservers.yml"
common_role_prefix: "{{role_prefix}}common/"
common_role_dirs:
- "{{common_role_prefix}}"
- "{{common_role_prefix}}tasks/"
- "{{common_role_prefix}}handlers/"
- "{{common_role_prefix}}templates/"
- "{{common_role_prefix}}vars/"
- "{{common_role_prefix}}defaults/"
- "{{common_role_prefix}}meta/"
common_role_files:
- "{{role_prefix}}common/tasks/main.yml"
- "{{role_prefix}}common/handlers/main.yml"
- "{{role_prefix}}common/templates/example.conf.j2"
- "{{role_prefix}}common/vars/main.yml"
- "{{role_prefix}}common/defaults/main.yml"
- "{{role_prefix}}common/meta/main.yml"
tasks:
- name: initialize directory layout
file: path="{{item}}" state=directory mode=0755
with_items:
- "{{role_prefix}}"
- "{{var_dirs | list}}"
- name: initialize file layout
file: path="{{item}}" state=touch mode=0644
with_items:
- "{{env_files | union(playbook_files) | list}}"
- name: initialize common role directory layout
file: path="{{item}}" state=directory mode=0744
with_items:
- "{{common_role_dirs | list}}"
- name: initialize common role file layout
file: path="{{item}}" state=touch mode=0644
with_items:
- "{{common_role_files | list}}"
@justdoit0823
Copy link
Author

justdoit0823 commented Oct 4, 2017

we can use command ansible-playbook -c local ansible_template.yml -e dprefix=/Users/justdoit/workspace/devops/ansible/dev/ to initialize a directory layout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment