Hello Team,
I am putting broker: true and zookeeper: true in inventory file but i still getting below exception as its referred in j2 file
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleUndefinedVariable: 'broker' is undefined. 'broker' is undefined
fatal: [en1qa1-zookpr02.qa]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'broker' is undefined. 'broker' is undefined"}
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleUndefinedVariable: 'broker' is undefined. 'broker' is undefined
fatal: [en1qa1-zookpr01.qa: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'broker' is undefined. 'broker' is undefined"}
=================
jinja 2 file
{% if hostvars[inventory_hostname].zookeeper is defined %}
// jmx exporter scrape config for zookeeper
prometheus.scrape "jmx_exporter_zookeeper" {
targets = [
{"__address__" = "{{ v_kafka_host }}:{{ v_jmx_exporter_zookeeper_port }}"},
]
scrape_interval = "{{ v_jmx_exporter_scrape_interval }}"
forward_to = [prometheus.remote_write.mimir.receiver]
}
{% else %}
{% endif %}
{% if hostvars[inventory_hostname].broker is defined %}
// jmx exporter scrape config for Broker
prometheus.scrape "jmx_exporter_broker" {
targets = [
{"__address__" = "{{ v_kafka_host }}:{{ v_jmx_exporter_broker_port }}"},
]
scrape_interval = "{{ v_jmx_exporter_scrape_interval }}"
scrape_timeout = "{{ v_jmx_broker_scrape_timeout }}"
forward_to = [prometheus.remote_write.mimir.receiver]
}
{% else %}
{% endif %}
=======
kafka_inventory.yaml Inventory file
qa_kafka:
children:
cc:
children:
qa_eng_kafka_cluster:
hosts:
en1qa1-zookpr[01:03].qa:
zookeeper: true
en1qa1-kafka[01:06].qa:
broker: true
en1qa1-kafka[04:06].qa:
schema_registry: true
uc:
children:
=====================
running as below
ansible-playbook -i ansible/inventory/nonprod/kafka_inventory.yaml --limit qa_eng_kafka_cluster ansible/grafana-agent-play.yaml -u Kafka -b -k
qa_eng_kafka_cluster: hosts: en1qa1-zookpr[01:03].qa: broker: false schema_registry: false zookeeper: true en1qa1-kafka[01:06].qa: broker: true schema_registry: false zookeeper: false en1qa1-kafka[04:06].qa: broker: false schema_registry: true zookeeper: falseThe other way is to define all three variables in a higher group, setting them all to false, say, and then at the host level set only the ones you want to be true to true:
qa_kafka: vars: broker: false schema_registry: false zookeeper: false children: cc: children: qa_eng_kafka_cluster: hosts: en1qa1-zookpr[01:03].qa: zookeeper: true en1qa1-kafka[01:06].qa: broker: true en1qa1-kafka[04:06].qa: schema_registry: trueTo verify the variables are being set and associated with hosts appropriately, you can run:
$ ansible-inventory -i kafka_inventory.yaml --listCheers,
--
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-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/3245ff0a-26b3-4a7c-ae66-fdb1951a4797n%40googlegroups.com.
-- Todd
qa_kafka: children: cc: children: qa_eng_kafka_cluster: children: qa_eng_zoo: hosts: en1qa1-zookpr[01:03].qa qa_eng_bro: hosts: en1qa1-kafka[01:06].qa qa_eng_sch: hosts: en1qa1-kafka[04:06].qaThis creates three additional host groups: qa_eng_zoo, qa_eng_bro, and qa_end_sch. In your templates and whatnot, you can simply check for group membership.
-- Todd