├── .gitignore ├── CONTRIBUTING.rst ├── LICENSE ├── README.rst ├── cookiecutter.json ├── hooks └── post_gen_project.py └── {{cookiecutter.role_name}} ├── CONTRIBUTORS.txt ├── LICENSE.md ├── README.md ├── defaults └── main.yml ├── files └── .empty ├── handlers └── main.yml ├── meta └── main.yml ├── tasks └── main.yml └── templates └── .empty /.gitignore: -------------------------------------------------------------------------------- 1 | *.*~ 2 | .*.swp 3 | .*.swo 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | Contributing 3 | ============ 4 | 5 | Contributions are welcome, and they are greatly appreciated! Every 6 | little bit helps, and credit will always be given. 7 | 8 | You can contribute in many ways: 9 | 10 | Types of Contributions 11 | ---------------------- 12 | 13 | Report Bugs 14 | ~~~~~~~~~~~ 15 | 16 | Report bugs at https://github.com/iknite/cookiecutter-ansible-role/issues. 17 | 18 | If you are reporting a bug, please include: 19 | 20 | * Your operating system name and version. 21 | * Any details about your local setup that might be helpful in troubleshooting. 22 | * If you can, provide detailed steps to reproduce the bug. 23 | * If you don't have steps to reproduce the bug, just note your observations in 24 | as much detail as you can. Questions to start a discussion about the issue 25 | are welcome. 26 | 27 | Fix Bugs 28 | ~~~~~~~~ 29 | 30 | Look through the GitHub issues for bugs. Anything tagged with "bug" 31 | is open to whoever wants to implement it. 32 | 33 | Implement Features 34 | ~~~~~~~~~~~~~~~~~~ 35 | 36 | Look through the GitHub issues for features. Anything tagged with "enhancement" 37 | is open to whoever wants to implement it. 38 | 39 | Submit Feedback 40 | ~~~~~~~~~~~~~~~ 41 | 42 | The best way to send feedback is to file an issue at 43 | https://github.com/iknite/cookiecutter-ansible-role/issues. 44 | 45 | If you are proposing a feature: 46 | 47 | * Explain in detail how it would work. 48 | * Keep the scope as narrow as possible, to make it easier to implement. 49 | * Remember that this is a volunteer-driven project, and that contributions 50 | are welcome :) 51 | 52 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, Enrique Paredes 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or 5 | without modification, are permitted provided that the following 6 | conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following 13 | disclaimer in the documentation and/or other materials provided 14 | with the distribution. 15 | 16 | * Neither the name of border nor the names of its contributors 17 | may be used to endorse or promote products derived from this 18 | software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 28 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29 | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | POSSIBILITY OF SUCH DAMAGE. 33 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Cookiecutter Ansible Role 2 | ========================= 3 | 4 | Cookie cutter recipe to easily create `ansible roles`_. 5 | It infuses antigravity (or maybe not). 6 | 7 | .. _`ansible roles`: http://docs.ansible.com/playbooks_roles.html#roles 8 | 9 | Features 10 | -------- 11 | * Follows `best practices`_. 12 | * Only Creates the necessary files and folders. 13 | * Blazing fast creation, forget about file creation and focus in actions. 14 | 15 | .. _`best practices`: http://docs.ansible.com/playbooks_best_practices.html 16 | 17 | Usage 18 | ----- 19 | 20 | cookiecutter https://github.com/iknite/cookiecutter-ansible-role.git 21 | 22 | It begin to ask you configuration variables then you can enter tasks names, 23 | handlers names, and default variables. 24 | 25 | Inside a `Add name i.e ()` you can go to next section by entering 26 | an empty string. 27 | 28 | 29 | Example:: 30 | 31 | ROLE CONFIGURATION: 32 | =================== 33 | 34 | Should it have tasks? [Y/n] 35 | Add task name i.e (Install packages) Add some task 36 | Add task name i.e (Install packages) another task 37 | Add task name i.e (Install packages) 38 | 39 | Should it have handlers? [Y/n] 40 | Add handler name i.e (Restart uwsgi) restart something 41 | Add handler name i.e (Restart uwsgi) alert someone 42 | Add handler name i.e (Restart uwsgi) 43 | 44 | It should contain default variables?: [Y/n] 45 | Add variable i.e (operator: : drunken_master) var: name 46 | Add variable i.e (operator: : drunken_master) 47 | 48 | Should it have meta info? [Y/n] 49 | - Should it have dependencies? [Y/n] 50 | Add dependency i.e ({role: aptsupercow, var: 'value'}) {role: cool, version: latest} 51 | Add dependency i.e ({role: aptsupercow, var: 'value'}) 52 | 53 | Should it have templates? [Y/n] n 54 | 55 | Should it have files? [Y/n] y 56 | 57 | This will generate this folders (Please note the absence of templates folder):: 58 | 59 | . 60 | ├── CONTRIBUTORS.txt 61 | ├── defaults 62 | │   └── main.yml 63 | ├── files 64 | ├── handlers 65 | │   └── main.yml 66 | ├── LICENSE.rst 67 | ├── meta 68 | │   └── main.yml 69 | ├── README.rst 70 | └── tasks 71 | └── main.yml 72 | 73 | Contributions 74 | ------------- 75 | 76 | All contributions are more than welcome, please do so. 77 | 78 | 79 | License 80 | ------- 81 | 82 | * 3-clause BSD license. 83 | * Copyright ©2014, Enrique Paredes 84 | * Enjoy it! 85 | 86 | -------------------------------------------------------------------------------- /cookiecutter.json: -------------------------------------------------------------------------------- 1 | { 2 | "full_name": "Enrique Paredes", 3 | "email": "enrique.iknite@gmail.com", 4 | "role_name": "Super.Role", 5 | "github_user": "iknite", 6 | "repo_name": "ansible-super-role", 7 | "short_description": "This Ansible Role infuses antigravity, you are warned", 8 | "release_date": "2014-06-12", 9 | "year": "2014", 10 | "version": "0.1.0", 11 | "min_ansible_version": "1.6", 12 | "allow_duplicates": "no" 13 | } 14 | -------------------------------------------------------------------------------- /hooks/post_gen_project.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from __future__ import unicode_literals, absolute_import, print_function 3 | 4 | import os 5 | import shutil 6 | from collections import OrderedDict 7 | from cookiecutter.prompt import read_user_yes_no 8 | 9 | try: 10 | input = raw_input 11 | except NameError: 12 | pass 13 | 14 | 15 | folders = OrderedDict() 16 | 17 | folders['tasks']= { 18 | 'question': '\nShould it have tasks? ', 19 | 'hint': ' Add task name i.e (Install packages) ', 20 | 'action': '- name: {}\n # TODO\n\n' 21 | } 22 | 23 | folders['handlers'] = { 24 | 'question': '\nShould it have handlers?', 25 | 'hint': ' Add handler name i.e (Restart uwsgi) ', 26 | 'action': '- name: {}\n # TODO\n\n' 27 | } 28 | 29 | folders['defaults'] = { 30 | 'question': '\nIt should contain default variables?: ', 31 | 'hint': ' Add variable i.e (operator: drunken_master) ', 32 | 'action': '{}\n\n' 33 | } 34 | 35 | folders['meta']= { 36 | 'question': '\nShould it have meta info? ', 37 | 'pre_hint': ' - Should it have dependencies? ', 38 | 'pre_action': '\ndependencies:\n', 39 | 'hint': ' Add dependency i.e ({role: aptsupercow, var: \'value\'}) ', 40 | 'action': ' - {}\n' 41 | } 42 | 43 | folders['templates'] = { 44 | 'question': '\nShould it have templates? ', 45 | } 46 | 47 | folders['files'] = { 48 | 'question': '\nShould it have files? ', 49 | } 50 | 51 | 52 | def configure_role(): 53 | print('\n\nROLE CONFIGURATION:\n===================') 54 | for folder_name, folder in folders.items(): 55 | if read_user_yes_no(folder['question'], default_value=u'yes'): 56 | 57 | try: 58 | # this file has to be there, git doesn't store empty folders. 59 | os.remove(os.path.join(folder_name, '.empty')) 60 | except OSError: 61 | pass 62 | 63 | if 'hint' in folder: 64 | with open('{}/main.yml'.format(folder_name), 'a') as fp: 65 | 66 | if 'pre_hint' in folder: 67 | if read_user_yes_no(folder['pre_hint'], default_value=u'yes'): 68 | fp.write(folder['pre_action']) 69 | else: 70 | continue 71 | 72 | action_name = input(folder['hint']) 73 | while action_name: 74 | fp.write(folder['action'].format(action_name)) 75 | action_name = input(folder['hint']) 76 | 77 | else: 78 | shutil.rmtree(folder_name) 79 | 80 | 81 | if __name__ == '__main__': 82 | configure_role() 83 | -------------------------------------------------------------------------------- /{{cookiecutter.role_name}}/CONTRIBUTORS.txt: -------------------------------------------------------------------------------- 1 | {{cookiecutter.full_name}} 2 | -------------------------------------------------------------------------------- /{{cookiecutter.role_name}}/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) {{ cookiecutter.year }}, {{ cookiecutter.full_name }} 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | 10 | * Neither the name of {{ cookiecutter.repo_name }} nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 13 | -------------------------------------------------------------------------------- /{{cookiecutter.role_name}}/README.md: -------------------------------------------------------------------------------- 1 | # {{cookiecutter.role_name}} 2 | 3 | {{cookiecutter.short_description}} 4 | 5 | ## Usage 6 | 7 | `ansible-galaxy install {{ cookiecutter.role_name }}` 8 | 9 | LICENSE: 3-clause BSD license. 10 | 11 | ## CONTRIBUTING 12 | 13 | `git clone git@github.com:{{cookiecutter.github_user}}/{{cookiecutter.repo_name}}` 14 | 15 | --- 16 | Copyright © {{cookiecutter.year}}, {{ cookiecutter.full_name }} 17 | -------------------------------------------------------------------------------- /{{cookiecutter.role_name}}/defaults/main.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iknite/cookiecutter-ansible-role/2e59ee63f9238d8f2a9a8957e09f149ff931bba4/{{cookiecutter.role_name}}/defaults/main.yml -------------------------------------------------------------------------------- /{{cookiecutter.role_name}}/files/.empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iknite/cookiecutter-ansible-role/2e59ee63f9238d8f2a9a8957e09f149ff931bba4/{{cookiecutter.role_name}}/files/.empty -------------------------------------------------------------------------------- /{{cookiecutter.role_name}}/handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | -------------------------------------------------------------------------------- /{{cookiecutter.role_name}}/meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | allow_duplicates: {{ cookiecutter.allow_duplicates }} 4 | 5 | 6 | galaxy_info: 7 | author: {{ cookiecutter.full_name }} 8 | description: {{ cookiecutter.short_description }} 9 | license: 3-clause BSD license. 10 | min_ansible_version: {{ cookiecutter.min_ansible_version }} 11 | platforms: 12 | - name: Ubuntu 13 | versions: 14 | 14.04 15 | categories: 16 | #- cloud 17 | #- cloud:ec2 18 | #- cloud:gce 19 | #- cloud:rax 20 | #- clustering 21 | #- database 22 | #- database:nosql 23 | #- database:sql 24 | #- development 25 | #- monitoring 26 | #- networking 27 | #- packaging 28 | #- system 29 | #- web 30 | 31 | 32 | -------------------------------------------------------------------------------- /{{cookiecutter.role_name}}/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | -------------------------------------------------------------------------------- /{{cookiecutter.role_name}}/templates/.empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iknite/cookiecutter-ansible-role/2e59ee63f9238d8f2a9a8957e09f149ff931bba4/{{cookiecutter.role_name}}/templates/.empty --------------------------------------------------------------------------------