Skip to content

Ansible

Run role against arbitrary host

From here. 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).

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

Run ad-hoc command against arbitrary 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).

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

Add timing information to playbook execution output

The below is from ansible.cfg. From here.

1
[defaults]
2
callback_whitelist = profile_tasks

Make verbose output more readable by using YAML instead of JSON

1
ANSIBLE_STDOUT_CALLBACK='yaml'

Debug variables without running entire playbook

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