Skip to content

Ansible

Run role against arbitrary host

Note the comma after the IP or FQDN as described here. Additional hosts can be added by supplying -i parameter with more arguments (comma at the end only if total count is 1).

Terminal window
ansible-playbook -i '<IP or FQDN>,' -u '<user name>' --extra-vars \
'ansible_winrm_server_cert_validation=ignore \
ansible_connection=winrm \
ansible_winrm_transport=credssp \
ansible_password=<password>' --tags '<tag value for a role>' playbook.yml

From here.

Run ad-hoc command against host

Replace the final ‘all’ with a more precise host pattern if you passed more than one IP or FQDN to the initial list (comma at the end only if total count is 1).

Terminal window
ansible -i '<IP or FQDN>,' -u '<user name>' --extra-vars \
'ansible_winrm_server_cert_validation=ignore \
ansible_connection=winrm \
ansible_winrm_transport=credssp \
ansible_password=<password>' -m 'win_shell' -a 'ipconfig' 'all'

Add timing information to output

The below is from an ansible.cfg file.

[defaults]
callback_whitelist = profile_tasks

From here.

Make verbose output more readable

ANSIBLE_STDOUT_CALLBACK='yaml'

Debug variables without playbook run

Terminal window
ansible -m debug <host> -a "var=hostvars[inventory_hostname].<variable>"