Brian said what to do, but left /how to do it/ as a (very worthwhile)
exercise for the reader.
It could look something like
when: group_names | select('search', '_broker' ) | length > 0 # matches
all the broker groups
when: group_names | select('search', kenv ~ '_app_zoo') | length > 0 #
app_zoo hosts in {{ kenv }} environment
when: "'kafka_dev' in group_names" # matches all your dev environment hosts
when: "'kafka_dev_app_zoo' in group_names" # matches all your dev app zoo
hosts
In jinja templates, those become if conditionals:
{% if group_names | select('search', '_broker' ) | length > 0 %}
{% if group_names | select('search', kenv ~ '_app_zoo') | length > 0 %}
{% if 'kafka_dev' in group_names" %}
{% if 'kafka_dev_app_zoo' in group_names" %}
Sorry to be slow to respond. It's been crazy busy at work.
—
Todd
On 4/22/24 2:12 PM, Sameer Modak wrote:
That was useful. But i still did not quite get how do we pass
*kafka_dev* in j2 or during runtime like we dont know before hand what
group we will be running against.*
*
*
*so in when condition can we pass something like this when group is
**kafka_dev***
*
On Friday, April 19, 2024 at 8:37:51 PM UTC+5:30 Todd Lewis wrote:
Oops. That second "children:" under "kafka:" shouldn't be there.
Otherwise, it's pretty close.
On Friday, April 19, 2024 at 10:58:32 AM UTC-4 Todd Lewis wrote:
It appears you are trying to define two different "*broker*"
groups: one as a child of the "*dev_kafka_cluster*" and
another as a child of "*qa_kafka_cluster*".
That isn't how groups work. There is only one "*broker*"
group. You have added hosts to the "*broker*" group in two places.
(Also, "*App*" as a group name should be lower-case letters.)
Let me suggest an alternative inventory/group arrangement that
implements this naming scheme:
*kafka[_{$env}[_{app,web,db}[_{zoo,broker,schema}]]]
*In this scheme, there isn't a "*broker*" group. Instead there
are groups named "*kafka_dev_app_broker*" and
"*kafka_qa_app_broker*" (and eventually a "*kafka_prd**" set I
imagine).
I call this type of group naming scheme "fully articulated" —
any group you care to specify is completely unambiguous. It's
a set of strict hierarchies (in this case there's only one
hierarchy: "*kafka*"), and hosts appear in a particular
hierarchy exactly once. (If you find yourself trying to inject
a host in two different places, you either need to rethink
your hierarchy's structure, or maybe you need two hierarchies.)
We have on occasion included an "*all*" environment (like
"*dev*" and "*qa*"). If you did that, there would be a
corresponding "*kafka_all**" group for any "*kafka_dev**" or
"*kafka_qa**" groups. Then you could target all the brokers
with "*kafka_all_app_broker*" instead of
"*kafka_dev_app_broker**,**kafka_qa_app_broker*". You would
have to decide if the benefit is worth the extra text you have
to maintain in your inventory.
Your inventory would look like this:
kafka:
children:
kafka_dev:
children:
kafka_dev_app:
children:
kafka_dev_app_zoo:
hosts:
dev1-main-zookpr[01:05].dev
kafka_dev_app_broker:
hosts:
dev1-main-kafka[01:06].dev
kafka_dev_app_schema:
hosts:
dev1-main-kafka[01:06].dev
kafka_dev_web: […] # omitted for brevity,
kafka_dev_db: […] # but you get the idea.
children:
kafka_qa:
children:
kafka_qa_app:
children:
kafka_qa_app_zoo:
hosts:
qa1-main-zookpr[01:03].qa
kafka_qa_app_broker:
hosts:
qa1-main-kafka[01:06].qa
kafka_qa_app_schema:
hosts:
qa1-main-kafka[04:06].qa
kafka_qa_web: […] # omitted for brevity,
kafka_qa_db: […] # but you get the idea.
On 4/19/24 8:40 AM, Sameer Modak wrote:
I have an inventory something like this , each main cluster
has children like broker.
Now how do i run any tasks against perticular group.broker.
When we pass the group with --limit it does not work it runs
on all broker. Also main playbook has hosts:all in it
annsible/grafana-agent-play.yaml -i kafka_inventory.yaml
--limit qa_kafka_cluster -u sam -k -b
dev_kafka:
children:
App:
children:
dev_kafka_cluster:
children:
zookeeper:
hosts:
dev1-main-zookpr[01:05].dev
broker:
hosts:
dev1-main-kafka[01:06].dev
schema_registry:
hosts:
dev1-main-kafka[01:06].dev
uc:
children:
qa_kafka:
children:
App:
children:
qa_kafka_cluster:
children:
zookeeper:
hosts:
qa1-main-zookpr[01:03].qa
broker:
hosts:
qa1-main-kafka[01:06].qa
schema_registry:
hosts:
qa1-main-kafka[04:06].qa
========
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/0e0e0032-661b-4d2e-9fe4-347c08157d7bn%40googlegroups.com
<https://groups.google.com/d/msgid/ansible-project/0e0e0032-661b-4d2e-9fe4-347c08157d7bn%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
Todd
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/d1c3f22c-7378-4430-8b8d-1ce2733ebb50n%40googlegroups.com
<https://groups.google.com/d/msgid/ansible-project/d1c3f22c-7378-4430-8b8d-1ce2733ebb50n%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
Todd
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/7158f8f1-f357-4b0b-b74d-df63fcfc8d86%40gmail.com.