=========================
[](https://travis-ci.org/theforeman/foreman_ansible_inventory)
This script can be used as an Ansible dynamic inventory[1].
The connection parameters are set up via a configuration
file *foreman.ini*. *foreman.ini* is found using the following
order of discovery.
* `/etc/ansible/foreman.ini`
* Current directory of your inventory script.
* `FOREMAN_INI_PATH` environment variable.
## Variables and Parameters
The data returned from Foreman for each host is stored in a foreman
hash so they're available as *host_vars* along with the parameters
of the host and it's hostgroups:
"foo.example.com": {
"foreman": {
"architecture_id": 1,
"architecture_name": "x86_64",
"build": false,
"build_status": 0,
"build_status_label": "Installed",
"capabilities": [
"build",
"image"
],
"compute_profile_id": 4,
"hostgroup_name": "webtier/myapp",
"id": 70,
"image_name": "debian8.1",
...
"uuid": "50197c10-5ebb-b5cf-b384-a1e203e19e77"
},
"foreman_params": {
"testparam1": "foobar",
"testparam2": "small",
...
}
and could therefore be used in Ansible like:
- debug: msg="From Foreman host {{ foreman['uuid'] }}"
Which yields
TASK [test_foreman : debug] ****************************************************
ok: [foo.example.com] => {
"msg": "From Foreman host 50190bd1-052a-a34a-3c9c-df37a39550bf"
}
## Automatic Ansible groups
The inventory will provide a set of groups, by default prefixed by
'foreman_'. If you want to customize this prefix, change the
group_prefix option in /etc/ansible/foreman.ini. The rest of this
guide will assume the default prefix of 'foreman'
The hostgroup, location, organization, content view, and lifecycle
environment of each host are created as Ansible groups with a
foreman_<grouptype> prefix, all lowercase and problematic parameters
removed. So e.g. the foreman hostgroup
myapp / webtier / datacenter1
would turn into the Ansible group:
foreman_hostgroup_myapp_webtier_datacenter1
Furthermore Ansible groups can be created on the fly using the
*group_patterns* variable in *foreman.ini* so that you can build up
hierarchies using parameters on the hostgroup and host variables.
Lets assume you have a host that is built using this nested hostgroup:
myapp / webtier / datacenter1
and each of the hostgroups defines a parameters respectively:
myapp: app_param = myapp
webtier: tier_param = webtier
datacenter1: dc_param = datacenter1
The host is also in a subnet called "mysubnet" and provisioned via an image
then *group_patterns* like:
[ansible]
group_patterns = ["{app_param}-{tier_param}-{dc_param}",
"{app_param}-{tier_param}",
"{app_param}",
"{subnet_name}-{provision_method}"]
would put the host into the additional Ansible groups:
- myapp-webtier-datacenter1
- myapp-webtier
- myapp
- mysubnet-image
by recursively resolving the hostgroups, getting the parameter keys
and values and doing a Python *string.format()* like replacement on
it.
[1]: http://docs.ansible.com/intro_dynamic_inventory.html
Metadata
Release files for foreman-ansible-inventory 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| foreman_ansible_inventory-0.0.4.tar.gz | 19.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| foreman_ansible_inventory-0.0.4-py2-none-any.whl | Python 2 | none | any | Details |
Total release size: 25.8 kB
Release files / foreman_ansible_inventory-0.0.4.tar.gz
| Download URL | foreman_ansible_inventory-0.0.4.tar.gz |
|---|---|
| Size | 19.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6ba4658ed1ad5561f12139ec3f7b4c9784cdf6e5e392a0120e4e434ac60a28cb
|
|
BLAKE2b-256 checksum How to use checksums |
cad34d885e19cfc4f0d607129d2b0ef171b9a02f7cc3a645055acc588a230433
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / foreman_ansible_inventory-0.0.4-py2-none-any.whl
| Download URL | foreman_ansible_inventory-0.0.4-py2-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
bd4ac3fc1c859571df1b2ead6292258de80f6c0de9520d20f2f687e53f3a4b1d
|
|
BLAKE2b-256 checksum How to use checksums |
5af860946e2d187f779e4d7d63fdd762cb8c1a8334c0978011223159a278e36b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for foreman-ansible-inventory 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.