Not to sound snippy but did you test it to see?

I usually add a when condition to a debug task to test it.

- debug: msg="running on {{ inventory_hostname }}"
  when: inventory_hostname in groups["backend-servers"]

Then I run the playbook twice - once with the expected group, once with the 
other group.

$ ansible-playbook my_test_playbook.yml -i backend-servers
running on balance1
running on balance2
running on balance3
$

$ ansible-playbook my_test_playbook.yml -i web-servers
$

This is not actual output .. just a mock up.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

On Jan 26, 2023, at 1:11 PM, SysAdmin EM <emaw...@gmail.com> wrote:

Good morning everyone, this is my hosts file:

web-servers:
  hosts:
    web01:
      ansible_host: x.x.x.x
     web02:
       ansible_host: x.x.x.x

backend-servers:
   hosts:
     balance1:
       ansible_host: x.x.x.x
     balance2:
       ansible_host: x.x.x.x
     balance3:
       ansible_host: x.x.x.x

what is the correct way to call backend group servers? I tried this but it 
doesn’t work:

when: inventory_hostname in groups["backend-servers"]

Regards,

--
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
ansible-project+unsubscr...@googlegroups.com<mailto:ansible-project+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAGUDtnkya%3DwVKxwWxs9uxzxw9ti2LPvvaq2mDrz9mFnkY65SYw%40mail.gmail.com<https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2FCAGUDtnkya%253DwVKxwWxs9uxzxw9ti2LPvvaq2mDrz9mFnkY65SYw%2540mail.gmail.com%3Futm_medium%3Demail%26utm_source%3Dfooter&data=05%7C01%7Cwalter.rowe%40nist.gov%7C242f1b98cb0e4e01785208daffc8dc7d%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638103535397436177%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=MUPgSoJiqVq0ZIV2rQ%2B9m3MbMnGFsdQdeuhj5lJQWyI%3D&reserved=0>.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1DE7A519-F673-4F4F-B5E2-8D5B5F266494%40nist.gov.

Reply via email to