An open API service indexing awesome lists of open source software.

https://github.com/paralect/ansible-profiles-plugin

Profiles management plugin for Ansible
https://github.com/paralect/ansible-profiles-plugin

Last synced: 10 months ago
JSON representation

Profiles management plugin for Ansible

Awesome Lists containing this project

README

          

# Ansible Profiles Plugin

Profiles management plugin for Ansible.

## About

Ansible uses two folders to manage variables: `host_vars` and `group_vars`. This plugin uses additional folder, `profiles`, which may consists of unlimited hierarchy of folders to represent profiles. There is only one file inside each profile directory: `vars.yml`. Child profiles always overwrite variables from parent profile. We will show how it works soon.

Here is a possible structure of `profiles` folder:

```
[profiles]
[production]
[datacenter1]
vars.yml
[datacenter2]
vars.yml
vars.yml
[stage]
vars.yml
[qa]
vars.yml
[local]
[john]
vars.yml
[tom]
vars.yml
[brett]
vars.yml
vars.yml
...
vars.yml
```

It defines several profiles, for instance:

1. `production`
2. `production/datacenter1`
3. `local`
4. `local/john`
5. _root_ profile (represented by empty string: `""`)
6. ...

## Turn on profile

There are two ways to select profile.

Create `.profile` file in the same folder, where your `profiles` folder is located with the
following content:

```
profile: production/datacenter1
```

This file should be marked as ignored for your SCM tool (git, svn etc.).

Or set environment variable `ANSIBLE_PROFILE`:

```
exports ANSIBLE_PROFILE=production/datacenter1
```

If you have specified `ANSIBLE_PROFILE` environment variable, then `.profile` file will be ignored.

## Example

If `profiles/vars.yaml` has the following configuration:

```
db_port: 4000
host: roothost.com
author: StarCompany
```

And `profiles/local/vars.yml` has the following configuration:

```
db_port: 5000
host: localhost
```

And finally `profiles/local/john/vars.yml` has the following configuration:

```
db_port: 6000
host: johnhost.org
```

Then, _root_ profile will have the following state (it is completely equal
to the content of `profiles/vars.yml`):

```
db_port: 4000
host: roothost.com
author: StarCompany
```

Profile `local` will be:

```
db_port: 5000
host: localhost
author: StarCompany
```

Profile `local/john` will be:

```
db_port: 6000
host: johnhost.org
author: StarCompany
```

## Installation

Copy `profiles.py` file to `vars_plugins` folder near your root playbooks:

```
[group_vars]
[host_vars]
[profiles]
[vars_plugins]
profiles.py <-- here is a Profiles Plugin
hosts
playbook.yml
```

Turn on profile by either creating `.profile` file near your root playbooks with
the following content:

profile: relative/path/to/your/profile

or set `ANSIBLE_PROFILE` environment profile:

exports ANSIBLE_PROFILE=relative/path/to/your/profile

#### Global install

You also can install this plugin globally, by coping `profiles.py` to the ansible `vars_plugins` folder. In order to find the path to `vars_plugins` folder refer to `ansible.cfg` (location of this file is specific to your distribution, on Ubuntu it is located in `/etc/ansible/ansible.cfg` and/or `~/.ansible.cfg`