在剧本 运行 之后访问 ansible 剧本结果
Access ansible playbook results after run of playbook
我是 运行 一个在我看不到的远程机器(客户端)上使用 ansible-pull
的 ansible 脚本。
我想确认一下:
- ansible 剧本执行成功然后应该发送摘要
- ansible 剧本如果未成功执行,应发送失败内容摘要
启用 ansible 日志将信息存储在某些日志文件中,但想知道我是否可以通过 ansible 中预定义的一些变量获得以下 ansible 输出的结果。
PLAY [localhost] **************************************************************
GATHERING FACTS ***************************************************************
ok: [localhost]
TASK: [Install the hello package] *********************************************
ok: [localhost] => {"changed": false}
TASK: [Install the cmatrix package] *******************************************
ok: [localhost] => {"changed": false}
PLAY RECAP ********************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0
如果没有,那么我将不得不编写自定义脚本来解析日志,将信息保存在机器上的某个数据库中并将其发送回我们的服务器。
据我所知,没有可以从中获取数据的变量。
但这需要一个 callback plugin. Have a look at the plugin log_plays. It writes its own logfile. You could intercept all the messages, collect them and at the end (define a method def playbook_on_stats(self, stats):
in your plugin) do with it whatever you want. There also is the mail plugin 来发送有关失败任务的电子邮件。
我是 运行 一个在我看不到的远程机器(客户端)上使用 ansible-pull
的 ansible 脚本。
我想确认一下:
- ansible 剧本执行成功然后应该发送摘要
- ansible 剧本如果未成功执行,应发送失败内容摘要
启用 ansible 日志将信息存储在某些日志文件中,但想知道我是否可以通过 ansible 中预定义的一些变量获得以下 ansible 输出的结果。
PLAY [localhost] **************************************************************
GATHERING FACTS ***************************************************************
ok: [localhost]
TASK: [Install the hello package] *********************************************
ok: [localhost] => {"changed": false}
TASK: [Install the cmatrix package] *******************************************
ok: [localhost] => {"changed": false}
PLAY RECAP ********************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0
如果没有,那么我将不得不编写自定义脚本来解析日志,将信息保存在机器上的某个数据库中并将其发送回我们的服务器。
据我所知,没有可以从中获取数据的变量。
但这需要一个 callback plugin. Have a look at the plugin log_plays. It writes its own logfile. You could intercept all the messages, collect them and at the end (define a method def playbook_on_stats(self, stats):
in your plugin) do with it whatever you want. There also is the mail plugin 来发送有关失败任务的电子邮件。