Coder Social home page Coder Social logo

springerpe / concourse-ansible-resource Goto Github PK

View Code? Open in Web Editor NEW
18.0 5.0 16.0 29 KB

Concourse resource type to run ansible playbooks

License: MIT License

Python 90.49% Shell 3.70% Dockerfile 5.81%
concourse concourse-resource concourse-ci-resource concourse-ci concourse-pipeline

concourse-ansible-resource's Introduction

Ansible Concourse Resource

This is Ansible resource for Concourse to be able to execute Ansible playbooks from concourse.

This a pure Python implementation using the Ansible API. It does not use the binary commands and it defines an output plugin to send the ansible execution logs to stderr as it is required by concourse (see ansible/callbacks/concourse.py).

The ansible default configuration (in /etc/ansible) is defined in ansible folder.

Source Configuration

Parameters available to use in the resource definition. None of then are required, but probably you will need to setup private_key, remote_user and inventory:

  • private_key: A string containing the ssh private key used for ssh connections.
  • remote_user: Remote user used to establish a ssh connection.
  • remote_pass : If private_key is not provided, password for remote_user.
  • vault_password: Ansible vault password to access to encrypted files with variables.
  • extra_vars: Key-value dictionary with variables used in the playbooks.
  • inventory: Dictionary for inventory definition:
    • file: Defaults to inventory.ini file name for inventory.
    • path: Folder where the hosts inventory file will be created (if needed) and additional inventory files can be defined: group_vars and host_vars are. Defaults to inventory.
    • hosts: Ansible inventory definition specifying the hosts, hosts groups and variables.
    • executable: Path to a dynamic inventory executable.
  • become: If true, execute playbooks as become_user. Usually not needed at this level.
  • become_method: Ansible become method (defaults to sudo).
  • become_user: User to run for privileged tasks (defaults to root).
  • become_pass: Password in order to become becomer_user with become_method.
  • ssh_common_args: ssh client additional arguments to establish ssh connections.
  • forks: Number of parallel execution threads for hosts groups.
  • tags: Limit playbook execution to only tasks tagged with this tags.
  • skip_tags: Tasks of playbook with these tags will be skipped.

Behavior

check, in

Currently this resource only supports the put phase of a job plan, so these are effectively no-ops. This will likely change in the future.

out: Run an Ansible playbook

Run a an ansible playbook, sending the output to stderr by using a concourse stdout plugin (defined in the default configuration ansible/ansible.cfg).

The parameters are almost the same as the ones in source, except private_key and playbook (only in out).

Parameters

  • src: Base folder where all the ansible resources are (inventory, playbook, ...)
  • playbook: Playbook file name to execute.
  • remote_user: Remote user used to establish a ssh connection.
  • remote_pass : If private_key is not provided, password for remote_user.
  • vault_password: Ansible vault password to access to encrypted files with variables.
  • extra_vars: Key-value dictionary with variables used in the playbooks.
  • inventory: Dictionary for inventory definition:
    • file: Defaults to inventory.ini file name for inventory.
    • path: Folder where the hosts inventory file will be created (if needed) and additional inventory files can be defined: group_vars and host_vars are. Defaults to inventory.
    • hosts: Ansible inventory definition specifying the hosts, hosts groups and variables.
    • executable: Path to a dynamic inventory executable.
  • become: If true, execute playbooks as become_user. Usually not needed at this level.
  • become_method: Ansible become method (defaults to sudo).
  • become_user: User to run for privileged tasks (defaults to root).
  • become_pass: Password in order to become becomer_user with become_method.
  • ssh_common_args: ssh client additional arguments to establish ssh connections.
  • forks: Number of parallel execution threads for hosts groups.
  • tags: Limit playbook execution to only tasks tagged with this tags.
  • skip_tags: Tasks of playbook with these tags will be skipped.

Example Pipeline

---
resource_types:
- name: ansible
  type: docker-image
  source:
    repository: platformengineering/concourse-ansible-resource

resources:
- name: ansible-playbook
  type: git
  source:
    uri: [email protected]:springerpe/repository.git
    branch: master
    private_key: {{github-private-key}}
- name: ansible-executor
  type: ansible
  source:
    private_key: {{ansible-private-key}}
    remote_user: ansible
    inventory:
      hosts:
        webservers: 
        - "host2.example.com"
        - "host3.example.com"
        atlanta:
            hosts:
            - "host1.example.com"
            - "host4.example.com"
            - "host5.example.com"
            vars:
              b: false
            children:
            - marietta
        marietta:
        - "host6.example.com"

jobs:
- name: run-ansible
  plan:
  - get: ansible-playbook
  - put: ansible-executor
    params:
      src: "ansible-playbook"
      playbook: "site.yml"

Another pipeline example:

---
resource_types:
- name: ansible
  type: docker-image
  source:
    repository: platformengineering/concourse-ansible-resource

resources:
- name: ansible-playbook
  type: git
  source:
    uri: [email protected]:springernature/ee-ansible-ironic-standalone.git
    branch: master
    private_key: |
        -----BEGIN RSA PRIVATE KEY-----
        ..................................................................
        -----END RSA PRIVATE KEY-----

- name: ansible-executor
  type: ansible
  source:
    private_key: {{ansible-private-key}}
    remote_user: {{ansible-remote-user}}
    vault_password: {{ansible-vault-password}}


jobs:
- name: run-ansible
  plan:
  - get: ansible-playbook
    params:
      submodules: all
  - put: ansible-executor
    params:
      src: "ansible-playbook"
      inventory:
        path: "inventory"
        file: "pe-prod-dogo-ironic-01.ini"
      playbook: "setup.yml"

Ansible playbook repo structure

This is an example of a playbook git repository:

.
├── playbook.yml
├── inventory
│   ├── static_inventory.ini
│   └── group_vars
│       └── group.yml
├── [roles]
│   ├── role1
│   └── role2
├── [tasks]
│   ├── task1.yml
│   └── task1.yml
├── [files]
│   └── file.bin
└── [vars]
    ├── secrets.yml
    └── other_vars.yml

Author

Jose Riguera [email protected] (c) 2017 Springer Nature Platform Engineering

concourse-ansible-resource's People

Contributors

fiftin avatar jriguera avatar lunascat avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

concourse-ansible-resource's Issues

Add git binary

It would be nice if image could add git binary so it is usable with ansible-galaxy to install requirements that are hosted in a git repository

Cannot use ansible-galaxy

It would be nice if we could give a requirement file as option and get ansible-galaxy install requirements before ansible-playbook executes. This is the common way to use ansible-playbook.

Playbook Not Found

Hi
I am trying use this resource type to execute my ansible playbook but always getting can not find playbook error.Is there any specific folder structure need to be followed?

Traceback (most recent call last):
File "/opt/resource/out", line 449, in
rcode = r.run(os.path.basename(file))
File "/opt/resource/resource.py", line 146, in run
rcode, response = self.update(self.workfolder, source, params)
File "/opt/resource/out", line 436, in update
config = self.configure(folder, source, params)
File "/opt/resource/out", line 389, in configure
raise ValueError(msg)
ValueError: Cannot find playbook file '/tmp/build/put/ansible-playbook/site.yml'

Thanks
Sasikanta

Cannot use "extra_vars"

When trying to pass any extra_vars to the "put" step of my Ansible resource, I receive the following error:

Traceback (most recent call last):
  File "/opt/resource/out", line 449, in <module>
    rcode = r.run(os.path.basename(__file__))
  File "/opt/resource/resource.py", line 146, in run
    rcode, response = self.update(self.workfolder, source, params)
  File "/opt/resource/out", line 437, in update
    exitcode, stdout, stats = PlaybookCLI(config, self.logger).run()
  File "/opt/resource/out", line 122, in run
    variable_manager.extra_vars = load_extra_vars(loader=loader, options=extra_vars)
  File "/usr/lib/python2.7/site-packages/ansible/utils/vars.py", line 121, in load_extra_vars
    for extra_vars_opt in options.extra_vars:
AttributeError: 'dict' object has no attribute 'extra_vars'

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.