Skip to content

Ansible Code Snippets โ€‹

Deploy to docker โ€‹

[host_group_name]
<container_name> ansible_connection=docker

Debug โ€‹

yml
- name: IPs
  ansible.builtin.debug:
    var: <var_name>

- name: Define private_ip
  debug:
    var: hostvars[inventory_hostname].ansible_eth0

Multicast Command โ€‹

bash
export ANSIBLE_HOST_KEY_CHECKING=false

ansible -i hosts 'LIMIT' \
    --user=<user> \
    --private-key=<key> \
    -f 10 -m shell -a \
	'echo 1'

IMPORTANT

Notice that sometimes host file will assign default username:

ini
[all:vars]
ansible_user = aaa

In this case, --user will not affect.

Get IPs โ€‹

yml
- name: IPs
  ansible.builtin.debug:
    var: ansible_all_ipv4_addresses

To specific network interface: ansible_eth0.ipv4.address

Changelog

Just observe ๐Ÿ‘€