How to use group_vars in ansible templates

270 views
Skip to first unread message

Bala Mutyam

unread,
Feb 10, 2020, 6:21:34 AM2/10/20
to Ansible Project
Hi there,

Could someone help me with how to template this config like below please?

cluster_formation.classic_config.nodes.1 = rabbit@rabbitmq-1
cluster_formation.classic_config.nodes.2 = rabbit@rabbitmq-2
cluster_formation.classic_config.nodes.3 = rabbit@rabbitmq-3


I would like to change nodes.1,2,3 & rabbit@anisble_hostname

Thanks

Stefan Hornburg (Racke)

unread,
Feb 10, 2020, 8:01:58 AM2/10/20
to ansible...@googlegroups.com
So you want to loop over a host group to get this configuration above?

Regards
Racke

>
> Thanks
>
> --
> 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 <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/f4b3c9f2-a4b3-4052-86a1-06e6dde25054%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/f4b3c9f2-a4b3-4052-86a1-06e6dde25054%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

Mr. sHamEem/ IT Club Hub

unread,
Feb 10, 2020, 9:05:02 AM2/10/20
to ansible...@googlegroups.com
Hi there ,

i am getting following issue to connect with my Cisco CISCO2951/K9 (revision 1.1)  router any one please help me !

===================
fatal: [router1]: FAILED! => {
    "changed": false,
    "msg": "Illegal info request from server"
}
==================

root@firstansible:/etc/ansible#  

## db-[99:101]-node.example.com
[IOS]
router1 ansible_ssh_user=bdcom ansible_host=210.4.64.100 ansible_network_os=ios ansible_connection=network_cli
router2 ansible_host=10.10.1.254

root@firstansible:/etc/ansible# ansible-playbook aminul1.yml -vvv
ansible-playbook 2.9.4
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.12 (default, Oct  8 2019, 14:14:10) [GCC 5.4.0 20160609]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Parsed /etc/ansible/hosts inventory source with ini plugin

PLAYBOOK: aminul1.yml **************************************************************************************************************************************************
1 plays in aminul1.yml

PLAY [router1] *********************************************************************************************************************************************************
META: ran handlers

TASK [change hostname BDCOM-TEST] **************************************************************************************************************************************
task path: /etc/ansible/aminul1.yml:8
fatal: [router1]: FAILED! => {
    "changed": false,
    "msg": "Illegal info request from server"
}


PLAY RECAP *************************************************************************************************************************************************************
router1                    : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0  

root@firstansible:/etc/ansible# cat /etc/issue
Ubuntu 16.04.6 LTS \n \l


Bala Mutyam

unread,
Feb 12, 2020, 4:49:12 AM2/12/20
to Ansible Project
Yes. I managed get the config as below.

{% for host in groups['rabbitmq'] %}
cluster_formation.classic_config.nodes.{{ loop.index }} = rabbit@{{ hostvars[host]['ansible_hostname'] }}
{% endfor %}


On Monday, February 10, 2020 at 1:01:58 PM UTC, Stefan Hornburg (Racke) wrote:
On 2/10/20 12:21 PM, Bala Mutyam wrote:
> Hi there,
>
> Could someone help me with how to template this config like below please?
>
> cluster_formation.classic_config.nodes.1 = rabbit@rabbitmq-1
> cluster_formation.classic_config.nodes.2 = rabbit@rabbitmq-2
> cluster_formation.classic_config.nodes.3 = rabbit@rabbitmq-3
>
>
> I would like to change nodes.1,2,3 & rabbit@anisble_hostname

So you want to loop over a host group to get this configuration above?

Regards
       Racke

>
> Thanks
>
> --
> 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

Dick Visser

unread,
Feb 12, 2020, 7:54:52 AM2/12/20
to ansible...@googlegroups.com
You forgot to post your playbook

--
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/CAEV3LdpKBgJCgyXEUBx-M8gFJGVAT2x6xP9EcNehS3GZbaw7VA%40mail.gmail.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.
Reply all
Reply to author
Forward
0 new messages