├── README.md ├── group_vars ├── all └── group1 ├── host_vars └── hostname1 ├── production ├── roles └── common │ ├── README.md │ ├── defaults │ └── main.yml │ ├── handlers │ └── main.yml │ ├── meta │ └── main.yml │ ├── tasks │ └── main.yml │ ├── templates │ └── example-template.conf.j2 │ └── vars │ └── main.yml ├── site.yml └── staging /README.md: -------------------------------------------------------------------------------- 1 | # About This Repo # 2 | This is a skeleton of an Ansible home directory. You can control all of your application environments from this directory. If you work with multiple customers, you probably want to create a separate copy of this repo for each customer. 3 | 4 | This repo was designed to help new Ansible users to get up and running quickly. Feel free to add to it and add additional tips and tricks. Pull requests welcome. 5 | 6 | # Ansible Tips # 7 | In your roles directory, type ansible-galaxy init role_name in order to generate an empty skeleton for a new role you are working on. 8 | 9 | Example: 10 |
11 | ansible-galaxy init nginx 12 |13 | 14 | Check out [Ansible Examples](https://github.com/ansible/ansible-examples) for example playbooks. 15 | 16 | # Best Practices Directory Layout # 17 | 18 | Based on [Ansible Best Practices](https://docs.ansible.com/ansible/playbooks_best_practices.html#directory-layout) 19 | 20 |
21 | production # inventory file for production servers 22 | staging # inventory file for staging environment 23 | 24 | group_vars/ 25 | group1 # here we assign variables to particular groups 26 | group2 # "" 27 | host_vars/ 28 | hostname1 # if systems need specific variables, put them here 29 | hostname2 # "" 30 | 31 | library/ # if any custom modules, put them here (optional) 32 | filter_plugins/ # if any custom filter plugins, put them here (optional) 33 | 34 | site.yml # master playbook 35 | webservers.yml # playbook for webserver tier 36 | dbservers.yml # playbook for dbserver tier 37 | 38 | roles/ 39 | common/ # this hierarchy represents a "role" 40 | tasks/ # 41 | main.yml # <-- tasks file can include smaller files if warranted 42 | handlers/ # 43 | main.yml # <-- handlers file 44 | templates/ # <-- files for use with the template resource 45 | ntp.conf.j2 # <------- templates end in .j2 46 | files/ # 47 | bar.txt # <-- files for use with the copy resource 48 | foo.sh # <-- script files for use with the script resource 49 | vars/ # 50 | main.yml # <-- variables associated with this role 51 | defaults/ # 52 | main.yml # <-- default lower priority variables for this role 53 | meta/ # 54 | main.yml # <-- role dependencies 55 | 56 | webtier/ # same kind of structure as "common" was above, done for the webtier role 57 | monitoring/ # "" 58 | fooapp/ # "" 59 |60 | 61 | -------------------------------------------------------------------------------- /group_vars/all: -------------------------------------------------------------------------------- 1 | # A place to put variables that apply to all groups 2 | # Create a file in this directory called "webservers" to set variables 3 | # for the "webservers" group. 4 | -------------------------------------------------------------------------------- /group_vars/group1: -------------------------------------------------------------------------------- 1 | # here we assign variables to particular groups 2 | -------------------------------------------------------------------------------- /host_vars/hostname1: -------------------------------------------------------------------------------- 1 | # if systems need specific variables, put them here 2 | -------------------------------------------------------------------------------- /production: -------------------------------------------------------------------------------- 1 | # A place to put your production hosts 2 | # Examples: 3 | # 4 | # [webservers] 5 | # localhost ansible_connection=local ansible_python_interpreter=/usr/bin/python2.7 6 | # 7 | # [clusters] 8 | # beowolf.example.com ansible_ssh_user=root 9 | -------------------------------------------------------------------------------- /roles/common/README.md: -------------------------------------------------------------------------------- 1 | Role Name 2 | ======== 3 | 4 | A brief description of the role goes here. 5 | 6 | Requirements 7 | ------------ 8 | 9 | Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. 10 | 11 | Role Variables 12 | -------------- 13 | 14 | A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. 15 | 16 | Dependencies 17 | ------------ 18 | 19 | A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. 20 | 21 | Example Playbook 22 | ------------------------- 23 | 24 | Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: 25 | 26 | - hosts: servers 27 | roles: 28 | - { role: username.rolename, x: 42 } 29 | 30 | License 31 | ------- 32 | 33 | BSD 34 | 35 | Author Information 36 | ------------------ 37 | 38 | An optional section for the role authors to include contact information, or a website (HTML is not allowed). 39 | -------------------------------------------------------------------------------- /roles/common/defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # defaults file for common 3 | -------------------------------------------------------------------------------- /roles/common/handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # handlers file for common 3 | -------------------------------------------------------------------------------- /roles/common/meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: your name 4 | description: 5 | company: your company (optional) 6 | # Some suggested licenses: 7 | # - BSD (default) 8 | # - MIT 9 | # - GPLv2 10 | # - GPLv3 11 | # - Apache 12 | # - CC-BY 13 | license: license (GPLv2, CC-BY, etc) 14 | min_ansible_version: 1.2 15 | # 16 | # Below are all platforms currently available. Just uncomment 17 | # the ones that apply to your role. If you don't see your 18 | # platform on this list, let us know and we'll get it added! 19 | # 20 | #platforms: 21 | #- name: EL 22 | # versions: 23 | # - all 24 | # - 5 25 | # - 6 26 | #- name: GenericUNIX 27 | # versions: 28 | # - all 29 | # - any 30 | #- name: Fedora 31 | # versions: 32 | # - all 33 | # - 16 34 | # - 17 35 | # - 18 36 | # - 19 37 | # - 20 38 | #- name: opensuse 39 | # versions: 40 | # - all 41 | # - 12.1 42 | # - 12.2 43 | # - 12.3 44 | # - 13.1 45 | # - 13.2 46 | #- name: Amazon 47 | # versions: 48 | # - all 49 | # - 2013.03 50 | # - 2013.09 51 | #- name: GenericBSD 52 | # versions: 53 | # - all 54 | # - any 55 | #- name: FreeBSD 56 | # versions: 57 | # - all 58 | # - 8.0 59 | # - 8.1 60 | # - 8.2 61 | # - 8.3 62 | # - 8.4 63 | # - 9.0 64 | # - 9.1 65 | # - 9.1 66 | # - 9.2 67 | #- name: Ubuntu 68 | # versions: 69 | # - all 70 | # - lucid 71 | # - maverick 72 | # - natty 73 | # - oneiric 74 | # - precise 75 | # - quantal 76 | # - raring 77 | # - saucy 78 | # - trusty 79 | #- name: SLES 80 | # versions: 81 | # - all 82 | # - 10SP3 83 | # - 10SP4 84 | # - 11 85 | # - 11SP1 86 | # - 11SP2 87 | # - 11SP3 88 | #- name: GenericLinux 89 | # versions: 90 | # - all 91 | # - any 92 | #- name: Debian 93 | # versions: 94 | # - all 95 | # - etch 96 | # - lenny 97 | # - squeeze 98 | # - wheezy 99 | # 100 | # Below are all categories currently available. Just as with 101 | # the platforms above, uncomment those that apply to your role. 102 | # 103 | #categories: 104 | #- cloud 105 | #- cloud:ec2 106 | #- cloud:gce 107 | #- cloud:rax 108 | #- database 109 | #- database:nosql 110 | #- database:sql 111 | #- development 112 | #- monitoring 113 | #- networking 114 | #- packaging 115 | #- system 116 | #- web 117 | dependencies: [] 118 | # List your role dependencies here, one per line. Only 119 | # dependencies available via galaxy should be listed here. 120 | # Be sure to remove the '[]' above if you add dependencies 121 | # to this list. 122 | 123 | -------------------------------------------------------------------------------- /roles/common/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # tasks file for common 3 | -------------------------------------------------------------------------------- /roles/common/templates/example-template.conf.j2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattjbarlow/ansible-directory/e279d54edb43ec8a8e9fa0edb18d1045592e47ba/roles/common/templates/example-template.conf.j2 -------------------------------------------------------------------------------- /roles/common/vars/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # vars file for common 3 | -------------------------------------------------------------------------------- /site.yml: -------------------------------------------------------------------------------- 1 | # This is your main playbook you will run with: 2 | # ansible-playbook site.yml 3 | # You can kick off everything from this playbook. 4 | # Or, you can create separate playbooks in this directory for specific orchestration events. 5 | 6 | --- 7 | - name: apply common configuration to all nodes 8 | hosts: all 9 | user: root 10 | 11 | roles: 12 | - common 13 | 14 | -------------------------------------------------------------------------------- /staging: -------------------------------------------------------------------------------- 1 | # A place to put your stage hosts 2 | # Examples: 3 | # 4 | # localhost ansible_connection=local ansible_python_interpreter=/usr/bin/python2.7 5 | # beowolf.example.com ansible_ssh_user=root 6 | --------------------------------------------------------------------------------