我试图通过“ naresh”用户连接到目标服务器,并通过“ vijay”用户安装apache2,而“ vijay”用户是无密码的sudo用户,但我的剧本仍然出现故障。
ansible-playbook ds.yml -u naresh
cat ds.yml
---
- hosts: all
gather_facts: no
tasks:
- name: install apache2
command: apt install apache2 -y
register: abcd
become: yes
become_user: vijay
- debug: var=abcd
我遇到错误
fatal: [52.87.204.142]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"},"changed": true,"cmd": ["apt","install","apache2","-y"],"delta": "0:00:00.007384","end": "2019-11-06 14:25:58.346627","msg": "non-zero return code","rc": 100,"start": "2019-11-06 14:25:58.339243","stderr": "\nWARNING: apt does not have a stable CLI interface. Use with caution in scripts.\n\nE: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)\nE: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend),are you root?","stderr_lines": ["","WARNING: apt does not have a stable CLI interface. Use with caution in scripts.","","E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)","E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend),are you root?"],"stdout": "","stdout_lines": []}