rundeck-plugins / ansible-plugin

Ansible Integration for Rundeck
MIT License
333 stars 100 forks source link
ansible rundeck

Gitter Read more about Rundeck + Ansible

Please report any errors or suggestions!

MIGRATION NOTICE!!

In March of 2022 PagerDuty transferred this repo to the Rundeck Plugins organization. frozenice has done a wonderful job bringing this functionality to the Rundeck Community and has asked Rundeck to take over maintenance going forward. The move will allow us to better manage Issues and approve/merge Pull Requests, etc. The plugin will continue to be available to the Open Source community. Over the next few months our team will review all open PRs and merge or provide feedback/review comments as necessary.

Rundeck Ansible Plugin

This plugin brings basic Ansible support to Rundeck. It imports hosts from Ansible's inventory, including a bunch of facts, and can run modules and playbooks. There is also a node executor and file copier for your project.

No SSH-Keys need to be shared between Ansible and Rundeck (but can be), everything is run through either ansible or ansible-playbook (even the node import).

If you just want to give Rundeck and Ansible a quick try, check the Docker container instructions.

Components

The following bits are included:

Resource Model Source

Uses the default configured inventory to scan for nodes. Facts are discovered by default, but you can turn that off (although I highly recommend leaving it on).

Host groups are imported as tags, you can limit the import to just some selected patterns, if you want.

A bunch of facts are imported as attributes, e.g.:

Example of node attributes being automatically set by Ansible facts

Node Executor

This makes it possible to run commands via the "Commands" menu or the default "Command" node step in a job.

The command is passed to Ansible's shell module. You can specify which shell to use in the project settings.

File Copier

Enables usage of the default "Copy File" and (in combination with the above) "Script" node steps.

Files are transferred using Ansible's copy module.

Run Ansible Modules

Run any Ansible module! You can specify the module name and arguments.

Run Ansible Playbooks

Run a playbook as a node or workflow step (see note above). You can specify either a path to a playbook file (which must be accessible to Rundeck), or write an inline playbook.

Configuration

The Job Configuration, node, project and framework attributes can be used to customize how jobs are executed. On every run, the plugin will try to resolve the value associated with each ansible configuration by checking the configuration attributes in the following order:

Note that Node attributes are only evaluated for Node Executor jobs, Workflow Jobs (Playbook and Module) use only job configurations, and project/framework configurations.

The following configuration attributes can be set on the Node, or in the project.properties or framework.properties. To add them to project.properties, prefix them with "project." and for framework.properties prefix them with "framework.":

Password authentication can be performed in one of two ways:

  1. Create a Rundeck Job with a Secure Authentication Option, to pass in the password to use. The default name of this option should be "ansible-ssh-password", but you can change the name that is expected, if necessary.
  2. Use the Rundeck Key Storage Facility to store a password, and use the path to it as the ansible-ssh-password-storage-path Note that the first takes precedence in evaluation over the second.

Private Key authentication can be performed by using a full path to the ssh private key (make sure the file is owned by rundeck and access permissions are set to 0600) or using Key Storage Facility to store a private key.

Become password configuration is very similar to ssh password, you can use either Secure Authentication Option, the default option name should be "ansible-become-password" or use Key Storage Facility to store a password, and use the path to it as the ansible-become-password-storage-path. Also for become password just like ssh password the first takes precedence in evaluation over the second.

Requirements

Installation

Debugging

If anything goes wrong you can enable debugging for all components. Just enable the DEBUG log level for your jobs and add a Java system property named ansible.debug with the value true. You can do that for example in /etc/rundeck/profile, make sure to restart your rundeck service.

This will print extra info either in some logs (e.g. /var/log/rundeck/service.log) or the web console. If you file an issue, make sure to include as much information in your report as you can.

Contributing

Discussions and pull requests are welcome.