python lover
python lover

Reputation: 65

how to installed httpd package using Ansible in client in ubuntu machine

while installing httpd package using below ansible command i am getting

"appserver | FAILED! => {
    "cache_update_time": 1556452826,
    "cache_updated": false,
    "changed": false,
    "msg": "'/usr/bin/apt-get -y -o \"Dpkg::Options::=--force-confdef\" -o \"Dpkg::Options::=--force-confold\"     install 'mini-httpd'' failed: E: 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?\n",
    "rc": 100,
    "stderr": "E: 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?\n",
    "stderr_lines": [
        "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": []
}

ansible command:

ansible all -m apt  -a "name=mini-httpd state=present"

Upvotes: 2

Views: 2075

Answers (2)

Zeitounator
Zeitounator

Reputation: 44808

Edit: the below was still true up to ansible 2.7, although the -s | --sudo option was already announced as deprecated for a while and still arround for compatibility. Since ansible 2.8 you can only use -b | --become:

ansible all -b -m apt  -a "name=mini-httpd state=present"

E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied) E: Unable to acquire the dpkg frontend lock

Installing apt packages requires to be root on the target machine. If the current user you are connecting with on the target machine has sudo capabilities, try:

ansible all -s -m apt  -a "name=mini-httpd state=present"

And see ansible --help for all other privileges escalation option if this does not solve your issue.

Upvotes: 1

Adeel Zaheer
Adeel Zaheer

Reputation: 11

-s is not valid and if you want to install package you would need to be root.
You will the need option --become.

So the command will look like this for apache2 on Ubuntu

ansible all -m apt -a "name=apache2 state=present" --become

Upvotes: 1

Related Questions