无法在无业游民的盒子上运行ansible adhoc命令?

时间:2018-12-04 18:12:48

标签: ubuntu ansible vagrant

我正在尝试在无所事事的vms上运行ansible ad-hoc命令,但出现以下错误。

dynamic

我能够对其执行ping操作,并且ping结果如下所示

vagrant@10.0.0.12 | FAILED! => {
"cache_update_time": 1543885371,
"cache_updated": false,
"changed": false,
"msg": "'/usr/bin/apt-get -y -o \"Dpkg::Options::=--force-confdef\" -o \"Dpkg::Options::=--force-confold\"     install 'httpd'' failed: E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)\nE: Unable to lock the administration directory (/var/lib/dpkg/), are you root?\n",
"rc": 100,
"stderr": "E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)\nE: Unable to lock the administration directory (/var/lib/dpkg/), are you root?\n",
"stderr_lines": [
    "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?"
],
"stdout": "",
"stdout_lines": []

我搜索了两个堆栈溢出页面,试图更改权限,甚至删除了“ / var / lib / dpkg / lock”,但没有任何效果。

配置: Ubuntu 18.0虚拟机

无用的版本:无用的2.2.2

可用版本:vagrant@10.0.0.1 | SUCCESS => { "changed": false, "ping": "pong" }

我要运行的命令是:

ansible 2.7.4
  config file = None
  configured module search path = ['/Users/arunyantrapragada/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.7.1 (default, Nov  6 2018, 18:46:03) [Clang 10.0.0 (clang-1000.11.45.5)]

有人可以向我解释为什么会这样,并且在解决安全问题和删除“ / var / lib / dpkg / lock”中的锁定文件的中断时会采取什么解决方案。

2 个答案:

答案 0 :(得分:2)

您需要在命令中附加--sudo选项。否则,ansible将尝试以无业游民的用户身份运行apt-get,但是apt-get(如错误消息所提示)需要以root用户身份运行。

答案 1 :(得分:0)

ansible servers -i inventory -b -m apt -a "name=httpd state=present"

OR

ansible servers -i inventory -m apt -a "name=httpd state=present" -K(这将要求主机的sudo密码。)