Ansible2.0 python Api
Python 3.6.2 ansible 2.4.3.0
官方示例
注意: 默认官方示例中Ansbile的连接参数使用的是local,执行命令操作是在本地
示例修改后调用Ansible的模块执行远端命令:
1 | #!/usr/bin/env python |
{
“ngx-brazil-test01br-t001.gru1.wecash.net”: {
“changed”: true,
“end”: “2018-06-20 10:59:36.486658”,
“stdout”: “root”,
“cmd”: “whoami”,
“rc”: 0,
“start”: “2018-06-20 10:59:36.484856”,
“stderr”: “”,
“delta”: “0:00:00.001802”,
“invocation”: {
“module_args”: {
“warn”: true,
“executable”: null,
“_uses_shell”: true,
“_raw_params”: “whoami”,
“removes”: null,
“creates”: null,
“chdir”: null,
“stdin”: null
}
},
“_ansible_parsed”: true,
“stdout_lines”: [
“root”
],
“stderr_lines”: [],
“_ansible_no_log”: false
}
}
{
“ngx-brazil-test01br-t001.gru1.wecash.net”: {
“msg”: “root”,
“_ansible_verbose_always”: true,
“_ansible_no_log”: false,
“changed”: false
}
}
```