ansible 想必大家都不陌生,一种自动化运维工具,相较与SaltStack
管理比较简单,主要是不需要安装客户端,但是其多线程有先天性不足
今天那我们就先讲讲我们cmdb 其中一个小小的环节 python 调用ansible 的ad-hoc 和playbook
当然安装ansible 有yum 安装和 pip install 安装这边我们就不赘述了
1. 添加主机对象到指定主机组 add_host()
inventory.add_host(host='192.168.141.81',group='k8smaster',port=33)
1. 查看主机组资源 get_groups_dict()
inventory.get_groups_dict()
1. 获取指定的主机对象get_host()
inventory.get_host(hostname='192.168.141.81')
![2b602062e631bd77c7e49c28956e4135.png](https://img-blog.csdnimg.cn/img_convert/2b602062e631bd77c7e49c28956e4135.png)
VariableManager 调用
from ansible.vars.manager import VariableManager
VariableManager(l