简体   繁体   English

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

[英]Unable to run ansible adhoc commands on vagrant box?

I'm trying to run the ansible ad-hoc commands on vagrant vms, but getting the following error. 我正在尝试在无业游民的vms上运行ansible ad-hoc命令,但收到以下错误。

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": []

I was able to ping them fine, and the ping results are below, 我能够对其执行ping操作,并且ping结果如下所示,

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

I searched couple of stack overflow pages and tried to change the permissions and even removed the "/var/lib/dpkg/lock" but nothing worked. 我搜索了几个堆栈溢出页面,并试图更改权限,甚至删除了“ / var / lib / dpkg / lock”,但没有任何效果。

Configuration: Ubuntu 18.0 vms 配置:Ubuntu 18.0虚拟机

vagrant version: Vagrant 2.2.2 流浪汉版本:流浪汉2.2.2

ansible version: 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)] ansible版本: 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)]

Command I'm trying to run is: 我要运行的命令是:

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

Can someone please explain me why this is happening and what would be the solution with compromising the security issues and breaks for removing the lock file in "/var/lib/dpkg/lock". 有人可以解释一下为什么会发生这种情况,以及解决安全问题和删除“ / var / lib / dpkg / lock”中的锁定文件的中断的解决方案。

You need to append the --sudo option to your command. 您需要在命令后附加--sudo选项。 Otherwise, ansible will try to run apt-get as the vagrant user, but apt-get (as the error message hints at) needs to be run as root. 否则,ansible将尝试以无业游民的用户身份运行apt-get ,但是apt-get (如错误消息所提示)需要以root用户身份运行。

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 ( this will ask for sudo password for host machines.) ansible servers -i inventory -m apt -a "name=httpd state=present" -K (这将要求主机的sudo密码。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM