Giter VIP home page Giter VIP logo

cookiecutter-ansible-role's Introduction

Cookiecutter Ansible Role

  • Development branch: Build Status
  • Master branch: Build Status

Cookiecutter recipe to easily create ansible roles. This is a fork of the excellent iknite/cookiecutter-ansible-role project that I used as a starting point.

Features

  1. Follows Ansible best practices
  2. Follows Ansible Galaxy best practices
  3. Only Creates the necessary files and folders
  4. Blazing fast creation, forget about file creation and focus in actions
  5. Lint checks (Ansible-lint, yamllint)
  6. Test infrastructure already implemented (Test-kitchen, kitchen-ansible, kitchen-docker, InSpec + kitchen-inspec):
  7. Test your roles against multiple platforms using the power of Docker
  8. The life cycle of each platform is automatically managed by Test-kitchen
  9. Your roles can be verified with InSpec
  10. Travis-CI integration ready, with support for parallel builds: (.travis.yml, badges in README.md for development and master branches)
  11. Parallel test execution ready ({{cookiecutter.role_name}}/test/scripts/test-role.sh)

Usage

  1. Install cookiecutter: pip install cookiecutter
  2. cookiecutter https://github.com/ferrarimarco/cookiecutter-ansible-role

It will ask you questions about the structure of your role like tasks names, handlers names, and default variables. You can jump to the next question by entering an empty string.

Test the generated role

See README.md of the generated role.

Example

    ROLE CONFIGURATION:
    ===================

    Should it have tasks?  [Y/n]
      Add task name i.e (Install packages) Add some task
      Add task name i.e (Install packages) another task
      Add task name i.e (Install packages)

    Should it have handlers? [Y/n]
      Add handler name i.e (Restart uwsgi) restart something
      Add handler name i.e (Restart uwsgi) alert someone
      Add handler name i.e (Restart uwsgi)

    It should contain default variables?:  [Y/n]
      Add variable i.e (operator: : drunken_master) var: name
      Add variable i.e (operator: : drunken_master)      

    Should it have meta info?  [Y/n]
     - Should it have dependencies?  [Y/n]
        Add dependency i.e ({role: aptsupercow, var: 'value'}) {role: cool, version: latest}
        Add dependency i.e ({role: aptsupercow, var: 'value'})

    Should it have templates?  [Y/n] n

    Should it have files?  [Y/n] y

What is the rationale behind this fork?

While developing roles, I always wanted to test them in an ephemeral environment.

In my first role, I just ran a quick syntax check using the --syntax-check switch. Then I came across this blog post by Jeff Geerling and I was able to use his approach to use Travis CI to run my role against different platforms (via Docker), while also testing the its idempotence.

That methodology had a limitation: running tests on my local Docker environment was cumbersome and not practical as the process had too many "copy-and-paste-from-.travis.yml" steps. I managed to mitigate this issue to a certain extent by moving commands from .travis.yml to dedicated shell scripts (that you can now find in the test/scripts directory).

This partially solved the issue but the .travis.yml still contained the environment variables that described the platforms to run against (i.e. the Docker containers). So I still had some manual steps to tackle.

Then I stumbled upon Test-Kitchen. It's a testing framework with a plug-in interface. You can use it with various combinations of drivers (Docker, Vagrant...), provisioners (Ansible, Chef, Puppet...) and verifiers (RSpec, Serverspec, InSpec...). This completely abstracts the test environment from the "test runtime" environment, in the sense that you can run the same set of tests against different platforms, no matter the environment you use to run such tests. But wait, couldn't you just use plain docker for that? Yes, but you have to manage the life cycle of the test environments by yourself.

Examples of roles generated with this cookiecutter

cookiecutter-ansible-role's People

Contributors

ferrarimarco avatar iknite avatar julianpistorius avatar thatarchguy avatar yufeiminds avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cookiecutter-ansible-role's Issues

If/Else logic broken in post_gen_project.py

Thank you for this repo, it's a terrific time saver. One issue I noticed:

if read_user_yes_no(folder['question'], default_value=u'no'):
if read_user_yes_no(folder['pre_hint'], default_value=u'no'):

Should be

if read_user_yes_no(folder['question'], default_value=u'no') == 'yes':
if read_user_yes_no(folder['pre_hint'], default_value=u'no') == 'yes':

Otherwise they always evaluate to true and we are still prompted for the values if we set the default to 'no'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.