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
- Host: GitHub
- URL: https://github.com/paralect/ansible-profiles-plugin
- Owner: paralect
- License: gpl-3.0
- Created: 2013-11-30T15:30:56.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2013-12-01T21:01:48.000Z (about 12 years ago)
- Last Synced: 2025-01-21T15:49:23.571Z (11 months ago)
- Language: Python
- Homepage:
- Size: 145 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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`