我有简单的 ansible 剧本
- hosts: all
remote_user: myusername
become: yes
become_user: myusername
become_method: sudo
tasks:
- name: Install tmux
apt: name=tmux state=present
运行剧本时出现以下错误。
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