Once upon a time (I think before version 1.9) we could use -s for sudo on command line. Now it does not work. I am using version 2.85 on Ubuntu 18.04.
$ ansible all -m apt -a “name=httpd state=latest”
- this should give error lack of privilege, but instead ERROR! Extraneous options or arguments
$ ansible -s all -m apt -a “name=httpd state=latest”
- this used to work once upon a time. Also instead of -s
tried -b
and --become
- all give- ERROR! Extraneous options or arguments
Also tried --become-user=root
- same error
Is this command line syntax wrong- has all this changed over time?
How do we solve this - just use playbooks?
Update 1
The quote issue copy paste out of ms word - in word somehow it converts " to “ - that is how that transformation happened. So just use notepad.
Now replaced “ ”
with " "
and -b
option.
Tried this it went further
ansible -b all -m apt -a "name=httpd state=latest"
But it fails: [WARNING]: Could not find aptitude. Using apt-get instead
x.x.x.x | FAILED! => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"cache_update_time": 1570925983,
"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: Package 'httpd' has no installation candidate\n",
"rc": 100, ...
Not sure what this error means means - "install 'httpd'' failed: E: Package 'httpd' has no installation candidate". The target machine is ubuntu 18.04
This command works
apache2 (for debian) with -b (for sudo):
ansible -b all -m apt -a "name=apache2 state=latest"