troykinsella / concourse-ansible-playbook-resource

A Concourse CI resource for running Ansible playbooks
MIT License
40 stars 19 forks source link
ansible ansible-galaxy ansible-playbook automation concourse concourse-ci concourse-resource configuration-management

Concourse Ansible Playbook Resource

A Concourse CI resource for running Ansible playbooks.

The resource image contains the latest version of ansible, installed by pip, as of when the image was created. It runs ansible with python 3. See the Dockerfile for other supplied system and pip packages.

See Docker Hub for tagged image versions available.

Source Configuration

Most source attributes map directly to ansible-playbook options. See the ansible-playbook --help for further details.

The git_* attributes are relevant to referencing git repositories in the requirements.yml file which are pulled from during ansible-galaxy install.

Example

resource_types:
- name: ansible-playbook
  type: docker-image
  source:
    repository: troykinsella/concourse-ansible-playbook-resource
    tag: latest

resources:
- name: ansible
  type: ansible-playbook
  source:
    debug: false
    user: ubuntu
    ssh_private_key: ((ansible_ssh_private_key))
    vault_password: ((ansible_vault_password))
    verbose: v

Behaviour

check: No Op

in: No Op

out: Execute ansible Playbook

Execute ansible-playbook against a given playbook and inventory file, firstly installing dependencies with ansible-galaxy install -r requirements.yml if necessary.

Prior to running ansible-playbook, if an ansible.cfg file is present in the path directory, it is sanitized by removing entries for which the equivalent command line options are managed by this resource. The result of this sanitization can be seen by setting source.debug: true.

Parameters

Most parameters map directly to ansible-playbook options. See the ansible-playbook --help for further details.

Custom Setup Commands

As there are a myriad of Ansible modules, each of which having specific system dependencies, it becomes untenable for all of them to be supported by this resource Docker image. The setup_commands parameter of the put operation allows the pipeline manager to install system packages known to be depended upon by the particular playbooks being executed. Of course, this flexibility comes at the cost of having to execute the commands upon every put. That said, this Concourse resource does intend to supply a set of dependencies out of the box to support the most common or basic Ansible modules. Please open a ticket requesting the addition of a system package if it can be rationalized that it will benefit a wide variety of use cases.

Example

# Extends example in Source Configuration

jobs:
- name: provision-frontend
  plan:
  - get: master # git resource
  - put: ansible
    params:
      check: true
      diff: true
      inventory: inventory/some-hosts.yml
      playbook: site.yml
      path: master

Testing

docker build .

License

MIT © Troy Kinsella