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
挣扎的蓝藻
- 粉丝: 14w+
- 资源: 15万+
最新资源
- qaxbrowser-1.1.32574.52.exe (奇安信浏览器windows安装包)
- C#编写modbus tcp客户端读取modbus tcp服务器数据
- 某房地产瑞六补环境部分代码
- 基于Matlab实现无刷直流电机仿真(模型+说明文档).rar
- AllSort(直接插入排序,希尔排序,选择排序,堆排序,冒泡排序,快速排序,归并排序)
- 模拟qsort,改造冒泡排序使其能排序任意数据类型,即日常练习
- carsim+simulink联合仿真实现变道 包含路径规划算法+mpc轨迹跟踪算法 可选simulink版本和c++版本算法 可以适用于弯道道路,弯道车道保持,弯道变道 carsim内规划轨迹可视化
- 数组经典习题之顺序排序和二分查找和冒泡排序
- 永磁同步电机神经网络自抗扰控制,附带编程涉及到的公式文档,方便理解,模型顺利运行,效果好,位置电流双闭环采用二阶自抗扰控制,永磁同步电机三闭环控制,神经网络控制,自抗扰中状态扩张观测器与神经网络结合
- 基于 Oops Framework 提供的游戏项目开发模板,项目中提供了最新版本 Cocos Creator 3.x 插件与游戏资源初始化通用逻辑
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈