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* that resides in the same dir as the
inventory script.
## 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 hostgroup, location and organization of each host is created as
ansible group 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 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.
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
then *group_patterns* like:
[ansible]
group_patterns = ["{app_param}-{tier_param}-{dc_param}",
"{app_param}-{tier_param}",
"{app_param}"]
would put the host into the additional anisble groups:
- myapp-webtier-datacenter1
- myapp-webtier
- myapp
by reursively resolving the hostgroups, getting the parameter keys and
values performing doing a Python *string.format()* like replacement on
it.
[1]: http://docs.ansible.com/intro_dynamic_inventory.html
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
资源分类:Python库 所属语言:Python 资源全名:foreman_ansible_inventory-0.0.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
foreman_ansible_inventory-0.0.1.tar.gz (11个子文件)
foreman_ansible_inventory-0.0.1
PKG-INFO 405B
foreman.ini 236B
foreman_ansible_inventory.py 10KB
foreman_ansible_inventory.egg-info
PKG-INFO 405B
SOURCES.txt 266B
top_level.txt 1B
dependency_links.txt 1B
setup.cfg 59B
setup.py 1KB
.gitignore 53B
README.md 3KB
共 11 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 14w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功