For Ansible ad hoc commands (so, ansible commands outside of a playbook).
Questions tagged [ansible-ad-hoc]
42 questions
0
votes
1 answer
How to pass multiple values to "with_items" through ad-hoc command?
Here is the example ansible-playbook, if I want to pass the values of {{ item.first }} and {{ item.second }} through ad-hoc command from the terminal.
How can we do it ?
Thanks in advance..
---
- hosts: localhost
tasks:
- name: Here we are…

Sashi K
- 43
- 5
0
votes
1 answer
Ansible Ad-Hoc command with ssh keys
I would like to setup ansible on my Mac. I've done something similar in GNS3 and it worked but here there are more factors I need to take into account. so I have the Ansible installed. I added hostnames in /etc/hosts and I can ping using the…

Patryk Petryszen
- 1
- 3
0
votes
1 answer
AD-HOC edit /etc/sudoers from Ansible server side
I'm trying to add privilege to Ansible node via Ansible server using "lineinfile" via ad-hoc command as ROOT :
ansible -i rec-apache.inv -m lineinfile -a "path=/etc/sudoers \
line ='ansible-node1 ALL=(ALL:ALL) NO PASSWD:ALL'" --become-method=su…

Rayanaay
- 85
- 1
- 9
0
votes
1 answer
Ansible unable to access group_vars
I am not able to access my group_vars.
My current directory where i have my inventory file
[ansible@akashd1c inventory]$ pwd
/home/ansible/inventory
created group_vars directory in inventory
[ansible@akashd1c inventory]$ ls
group_vars …

akash
- 35
- 9
0
votes
1 answer
Error Recognition in Ansible Ad-hoc Commands
Is there a way to capture the stdout and stderr separately in bash, maybe as a tuple, for ansible ad-hoc commands? Something like: stdout, stderr= ansible -i hosts -m shell -a "command"

QuantAC
- 31
- 1
- 9
0
votes
1 answer
Get specific result entry with adhoc query
I have an inventory of about 10 hosts.
On all I want to check if a specific file exists. So I do:
ansible -m stat -a 'path=/the/file' all
And then I get a load of output because on most servers this file does actually exist.
But I only care for…

Martin B.
- 1,567
- 14
- 26
0
votes
2 answers
Pass multiple commands in ad-hoc mode in Cisco ios_command module
I would like to know how can I pass multiple show commands in ios_command module in ad-hoc mode.
Sample with just one command:
ansible all -m ios_command -a "commands='show version'"
Now here I would like to send another command, say show run or…

DilrajSK
- 5
- 7
0
votes
2 answers
Ansible Permission denied (public key) but ssh using same key works
I'm running this Ansible ad-hoc command on Ubuntu 16.x (ansible ver. 2.2.1.0 and 2.2.2.0)
ansible host_alias -a "df -h" -u USER
where host_alias is the defined the ansible hosts file (defines an ec2 instance and its .pem file).
the host file looks…

craig399
- 13
- 1
- 2
0
votes
1 answer
Ansible ad-hoc command filter JSON output by key or property
I'd like to filter the JSON output of ad-hoc ansible commands - e.g. grab the long list of "facts" for multiple hosts, and show only one that could be several levels deep, such as ansible_lsb.description, so I can quickly compare what versions of…

William Turrell
- 3,227
- 7
- 39
- 57
0
votes
3 answers
Vagrant and Ansible: ad-hoc command does not work
I'm trying to get Ansible and Vagrant working. In a folder (called Vagrant) I have a Vagrantfile, a hosts file and an ansible.cfg file with following contents:
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION =…

wiwa1978
- 2,317
- 3
- 31
- 67
-3
votes
1 answer
Cd command is not working in ansible when using in -a tag
I am using the below command and i am getting an error [Errno 2] No such file or directory: b'cd'
ansible servers -a "cd /etc/ansible"
I know that we can make use of playbooks but I just don't want to create, is there any possibility of executing…
-3
votes
1 answer
Do we have Ansible command to run user interactive shell script without using playbook?
I have below shell script which require user input:
read -e -p "Enter any string:" varible
echo 'Entered value is ::' $varible > abc.txt
I wanted to run this script which requires user input in multiple servers and achieved using below yml :
-…

sudhir tataraju
- 1,159
- 1
- 14
- 30