ansible - ansible_user 和 become_user 不工作
问题描述
我正在尝试通过用户“naresh”连接到目标服务器并通过用户“vijay”安装 apache2,“vijay”用户是无密码的 sudo 用户,但我的剧本仍然失败。
ansible-playbook ds.yml -u naresh
猫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": []}
解决方案
从您的错误消息中简单摘录:
无法获取 dpkg 前端锁 (/var/lib/dpkg/lock-frontend),你是 root 吗?
您作为第一个用户(naresh,没有管理员权限)连接成为第二个用户(vijay,也没有管理员权限)。这不起作用,ansible 不会发出任何其他升级。
你需要:
- 与具有完全 sudo 权限的用户联系(例如,在您的情况下看起来像是“vijay”)
- 成为具有管理权限的用户(即在这种情况下为 root,
become
如果您未指定,则使用时默认为 rootbecome_user
)
绝对是的!正如@Ash 所指出的,使用该apt
模块。
推荐阅读
- spring - spring-integraton:在 Aggregator 之后发起事务
- swift - 更好的替代 DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) 用于数据刷新
- bash - Jenkins shell 获取秘密 txt
- c - 文件中的内容在c程序中不存在
- python - 如何将 Django 存储库从 Github 部署到 cpanel 以进行自动更改
- javascript - 多个表头(头)行的问题
- c++ - 在 boost multi_index_container 中查找元素
- css - 我对 SVG 和谷歌字体“Monoton”有一个错误
- laravel - 如何在本地环境中的 vs 代码中使用 laravel 在 Vue 应用程序上实时重新加载?
- json - 根据类型跳过空值的序列化