【发布时间】:2015-10-17 21:48:15
【问题描述】:
我有简单的 ansible 剧本
- hosts: all
remote_user: myusername
become: yes
become_user: myusername
become_method: sudo
tasks:
- name: Install tmux
apt: name=tmux state=present
运行 playbook 时出现以下错误。
TASK: [Install tmux] **********************************************************
failed: [104.239.140.237] => {"failed": true}
stderr: E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
我参考http://docs.ansible.com/ansible/become.html提升用户的权限。
用户 'myusername' 属于 sudo 组。
$ sudo -l -U myusername
User myusername may run the following commands on this host:
(ALL : ALL) ALL
我能够在控制台上使用以下命令成功安装 tmux。在剧本中做同样的事情时,我不确定我错过了什么。
$ sudo apt-get install tmux
Reading package lists... Done
Building dependency tree
Reading state information... Done
【问题讨论】:
-
我认为您运行
sudo -l -U myusername的主机是远程ansible 目标,而不是您正在运行ansible-playbook的主机?还是都是同一个主机? -
它是远程节点。
标签: ubuntu-12.04 ansible sudo ansible-playbook privilege-elevation