Skip to content

odboy-tianjun/kenaito-ansible-go-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-ansible库应用

thank you for go-ansible authors

https://github.com/apenella/go-ansible

执行结果参考

执行成功

{
  "Command": "ansible all  --args 'ping 127.0.0.1 -c 2' --inventory 192.168.0.1,192.168.0.2 --module-name command --connection local",
  "Success": true,
  "Data": {
    "192.168.0.1": {
      "changed": 1,
      "failures": 0,
      "ignored": 0,
      "ok": 1,
      "rescued": 0,
      "skipped": 0,
      "unreachable": 0
    },
    "192.168.0.2": {
      "changed": 1,
      "failures": 0,
      "ignored": 0,
      "ok": 1,
      "rescued": 0,
      "skipped": 0,
      "unreachable": 0
    }
  },
  "ErrMsg": "",
  "StartTime": "2025-07-03 21:17:26",
  "EndTime": "2025-07-03 21:17:28",
  "Duration": 1566
}

执行失败

{
  "Command": "ansible all  --args 'pingxxxx 127.0.0.1 -c 2' --inventory 192.168.0.1,192.168.0.2 --module-name command --connection local",
  "Success": false,
  "Data": null,
  "ErrMsg": "Error during command execution.\n Command executed: ansible all  --args 'pingxxxx 127.0.0.1 -c 2' --inventory 192.168.0.1,192.168.0.2 --module-name command --connection local\n\n Environment variables:\nANSIBLE_LOAD_CALLBACK_PLUGINS=1\nANSIBLE_STDOUT_CALLBACK=json\n\n\texit status 2",
  "StartTime": "2025-07-03 21:20:07",
  "EndTime": "2025-07-03 21:20:08",
  "Duration": 497
}

About

go调用ansible、ansible-playbook并返回JSON数据

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages