3.1.2: awx 使用问题 - systemctl Interactive authentication required



0. 问题背景

在awx中执行systemctl,报错信息如下:

{
    "_ansible_parsed": true,
    "invocation": {
        "module_args": {
            "no_block": false,
            "force": null,
            "name": "test",
            "enabled": null,
            "daemon_reload": false,
            "state": "restarted",
            "user": false,
            "masked": null
        }
    },
    "changed": false,
    "_ansible_no_log": false,
    "msg": "Unable to restart service test: Failed to restart test.service: Interactive authentication required.\nSee system logs and 'systemctl status test.service' for details.\n"
}

其实这个报错信息是一个systemctl的报错。 尝试了如下办法:

  1. 去目标主机上增加systemctl的sudo命令的nopasswd授权,没有解决
  2. 在systemctl这个ansible task上显式的增加become: yes,问题竟然解决了

思考了一下,明明在awx的credential中已经增加了sudo的配置,为何还需要增加这个呢?经过对awx credential中的选项进行了初步了解,结论竟然是,我们需要显式的在playbook的yml文件中增加become: yes,只要在全局的yml文件中增加这个,以后就不用在其他task中增加了。

无语,可能awx的逻辑是,credential中只是给你配置上sudo的信息,而是否启用sudo,是需要在playbook中手动指定的。这个逻辑感觉有点怪怪的,但是总体也可以接受。