ansible_user和变为_user不起作用

我试图通过“ 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": []}
ygp47 回答:ansible_user和变为_user不起作用

您可以尝试使用ansible模块

- name: Install apache httpd  (state=present is optional)
  apt:
    name: apache2
    state: present
  become: yes
  become_user: vijay 
,

错误消息的简单摘录:

  

无法获取dpkg前端锁(/ var / lib / dpkg / lock-frontend),您是root吗?

您正在以第一用户身份(naresh,没有管理员权限)连接成为第二用户(vijay,也没有管理员权限)。这将不起作用,ansible不会发出任何其他升级。

您需要:

  1. 与具有完整sudo权限的用户联系(例如,在您的情况下看起来像是“ vijay”)
  2. 成为具有管理特权的用户(即,本例中为root,如果未指定become,则使用become_user时的默认权限)

当然可以!正如@Ash指出的那样,请使用apt模块。

本文链接:https://www.f2er.com/3151285.html

大家都在问