For Ansible ad hoc commands (so, ansible commands outside of a playbook).
Questions tagged [ansible-ad-hoc]
42 questions
3
votes
0 answers
Retry ansible ad-hoc when failure
In ansible playbook, we can detect the result of shell command, check then retry if having failure like this
---
# Retry when failure
- hosts: all
become: yes
become_user: www-data
vars:
ansible_python_interpreter: /usr/bin/python3
…

Hieu Huynh
- 1,005
- 11
- 18
2
votes
1 answer
Deleting multiple users with Ansible ad-hoc command
When running Ansible ad-hoc to remove users I was unable to feed multiple items to
module. Like this:
ansible -i my_inv all -m user -a"name={{ users }} state=absent" --check --extra-vars='{"users":["user1","user2"]}'
the output is:
server1 |…

Daniil Aksenov
- 60
- 1
- 8
2
votes
1 answer
Ansible adhoc command default user
Just exploring ansible and i am using ansible adhoc command
hosts file for ansible:
[cloud] node ansible_ssh_private_key_file=myfile.pem
ansible_user=ec2-user
$ ansible node -m ping -u ec2-user > works
$ ansible node -m ping > does not work
My…

Chandan Nayak
- 10,117
- 5
- 26
- 36
2
votes
1 answer
Can ansible ad-hoc tolerate some hosts failures?
I know ansible playbooks can set max_fail_percentage to allow the playbook to progress if at least that percentage of the hosts succeeded. However, I wanted to run an ad-hoc command that succeded (exit status 0) if at least a percentage of the hosts…

Capi Etheriel
- 3,542
- 28
- 49
1
vote
1 answer
Ansible ad-hoc task: How to separate output by host for clarity?
Is there a way to separate by host the output from a multi fork ad-hoc command?
I.e., if I ran:
ansible -a '/some/cmd' -f 2
The result comes back as one long stream like
host1 | CHANGED | rc=0 >>
Listing...
"some output"
host2 | CHANGED |…

Stephen Gibbons
- 13
- 3
1
vote
2 answers
Ansible ad hoc lookup
ansible all -m authorized_key -a 'name=automation key="{{lookup('file','/home/automation/.ssh/id.pub') }}' -C
ansible all -m authorized_key -a 'name=automation key="{{lookup('file','/home/automation/.ssh/id.pub') }}' -CD
ansible all -m…

Dennis
- 11
- 2
1
vote
1 answer
How can we prompt with some tag?
I was wondering if you can help me with some sample.
I know that modules like tag and when are helpful on this case. However, I am having hard times to create the yml file.
The goal is:
On server1, the commands are:
…
user1681128
1
vote
1 answer
How to supply both named and free_form arguments to ansible ad-hoc?
I ran across one of Ansible's modules that take free_form arguments along with named arguments - win_command. A specific example is given, where a powershell script is provided on stdin:
- name: Run an executable and send data to the stdin for the…

myxal
- 87
- 1
- 7
1
vote
3 answers
Ansible adhoc command with sudo
I'm tried to execute this command:
ansible somegroup -m raw -a "docker ps -a" --ask-pass -K --become-user root
But the error is:
Got permission denied while trying to connect to the Docker daemon
socket at unix:///var/run/docker.sock:
How to…

Meiram Chuzhenbayev
- 898
- 1
- 10
- 26
1
vote
1 answer
Ansible adhoc command returning a duplicate parameter found error when using raw module
I couldn't seem to find an answer to this query here already and can't seem to find anything with googling.
I am trying to run an adhoc command on a remote box using ansible and I keep getting "a duplicate paramter was found in the argument string"…

markus02
- 43
- 4
1
vote
1 answer
Why giving a host alias does not work with an Ansible Inventory file?
production (inventory file):
#main ansible_host=54.293.2785.210 ansible_port=22 ansible_ssh_user=ubuntu
54.293.2785.210 ansible_ssh_user=ubuntu
Running an ad-hoc command: ansible all -i production -a "hostname" Works!
But when I uncomment the first…

tread
- 10,133
- 17
- 95
- 170
1
vote
1 answer
simple quote issue for automate ansible ad-hoc command
I try to make shell script to automate some ansible ad-hoc command.
e.g.
/usr/bin/ansible app -m shell -a 'echo $HOME'
I write a simple script to automate this kind of tasks :
#!/bin/bash
set -x
ANS_BIN="/usr/bin/ansible"
pattern="app"
…

Antoine
- 4,456
- 4
- 44
- 51
1
vote
1 answer
Ansible ad hoc commands only work as sudo unless i'm in the hosts directory
I'm trying to work through getting started with ansible. When I try to run ad hoc commands with ansible, such as ansible all -m ping I have to either be in the same folder as my hosts file ~/Development/ansible/ or use sudo. I'm getting ready to…

Joe Madden
- 91
- 6
1
vote
1 answer
Ansible ad-hoc command works but same doesn't work in ansible playbook
I'm able to run the raw module using Ansible ad-hoc commands however, when run the playbook with same commands it fails with error:
invalid output was: Traceback (most recent call last):
File "/tmp/ansible-tmp-1418879078.47-138258829915016/setup",…

ankit tyagi
- 778
- 2
- 16
- 27
0
votes
0 answers
Ad hoc command with vmware.vmware_rest.*
Is it possible to use the ad hoc command with the Ansible modules vmware.vmware_rest.* ?
I am trying to run a simple comma to get virtual machine info.
ansible \
-m vmware.vmware_rest.vcenter_vm_info \
-a "vcenter_hostname=vcenter-ip…

Wael
- 77
- 2
- 10