Saravanan Jothilingam:
HI All,
I need to run ansible adhoc without the host file. How to achieve this?
ansible all -i “http://hostname.corp.domain.com|hostname.corp.domain.com,” -m “command” -a “uptime” ansible_user testuser -k
Error i got -> ansible: error: unrecognized arguments: ansible_user testuser
Lilo:
Make sure the arguments you use exist in your env.
Lilo:
You are passing an unrecognized argument to ansible. The argument “ansible_user” is not a valid argument for the ansible command. The “ansible_user” variable is typically used within a playbook or inventory to specify the username that ansible should use when connecting to remote hosts. It is not used as a command line argument.
Lilo:
ansible all -i "<http://hostname.corp.domain.com|hostname.corp.domain.com>," -m "command" -a "uptime" -u testuser -k
Lilo:
That’s how you can do it.
Lilo:
The -u
option is used to specify the ansible_user
(in this case, “testuser”) that Ansible should use for the remote connection. The -k
option is used to prompt for the SSH password.
Lilo:
Also, did you declare ansible_user in the inventory file?.
Saravanan Jothilingam:
@Lilo Thanks for sharing this cmd. It works fine with above cmd.