playbook --limit

This is my hosts:

[main_node]
1.2.3.4

[child_node]
1.2.3.4:2222

child_node is virtual container inside the main_node

why

ansible-playbook --diff --limit=child_node lc.yml --list-hosts

playbook: lc.yml

play #3 (main node): host count=1
1.2.3.4

play #4 (child node): host count=1
1.2.3.4

lc.yml

  • name: main node
    hosts: main_node

roles:

  • common

  • zabbix-agent

  • name: child node
    hosts: child_node

roles:

  • common

Ansible determines host uniqueness based on the hostname, in your case this is currently 1.2.3.4. What you need to do is use host aliases if you intend on having 2 hosts with the same IP but different ports. Such as:

[main_node]
main ansible_ssh_host=1.2.3.4

[child_node]
child ansible_ssh_host=1.2.3.4 ansible_ssh_port=2222