我遇到了一个问题,Ansible服务模块由于sudo密码问题而失败:
fatal: [192.168.1.10]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Shared connection to 192.168.1.10 closed.\r\n", "module_stdout": "sudo: a password is required\r\n", "msg": "MODULE FAILURE", "rc": 1}
to retry, use: --limit @/Volumes/HD/Users/user/Ansible/playbooks/stop-homeassistant.retry我的攻略只有一个任务,那就是停止服务。看起来是这样的:
---
- hosts: 192.168.1.10
tasks:
- name: Stop Homeassistant
become: true
service: name=home-assistant@homeassistant state=stopped enabled=yes或者,在systemd的情况下:
systemd: state=stopped name=home-assistant@homeassistant enabled=yes我的剧本是这样运行的:
ansible-playbook -u homeassistant playbooks/stop-homeassistant.yml但是,在该计算机上为该用户设置了无密码sudo (在/etc/sudoers.d中):
homeassistant ALL=(ALL) NOPASSWD:/bin/systemctl restart home-assistant@homeassistant
homeassistant ALL=(ALL) NOPASSWD:/bin/systemctl stop home-assistant@homeassistant 如果我以家庭助理身份ssh进入该框,并运行:
sudo systemctl stop home-assistant@homeassistanthome-assistant@homeassistant服务将在不询问sudo密码的情况下干净利落地停止。
你知道为什么systemctl命令在机器上作为用户运行得很好,但是在service/systemd模块中却失败了吗?
https://stackoverflow.com/questions/44476097
复制相似问题