Ansible: Get all the IP addresses of a group

I find the magic map extract here. main_nodes_ips: “{{ groups[‘mainnodes’] | map(‘extract’, hostvars, [‘ansible_host’]) | join(‘,’) }}” main_nodes_ips_with_port: “{{ groups[‘mainnodes’] | map(‘extract’, hostvars, [‘ansible_host’]) | join(‘:3000,’) }}:3000” An alternative(idea comes from here): main_nodes_ips: “{{ groups[‘mainnodes’] | map(‘extract’, hostvars, [‘ansible_eth0’, ‘ipv4’, ‘address’]) | join(‘,’) }}” (Suppose the interface is eth0)

Dashes in jinja templates

Turns out that + and – are there for whitespace control purpose. You can manually disable the lstrip_blocks behavior by putting a plus sign (+) at the start of a block […] You can also strip whitespace in templates by hand. If you put an minus sign (-) to the start or end of an … Read more

Flask – Accessing the config variable in the template

There are a few global variables that are passed in the templates context by default by flask (here is the complete list), one of them being config, which allows you to access the application configuration from templates. Being a dictionary, it can be accessed using the syntax config[‘MY_CONFIGURATION’] or config.MY_CONFIGURATION (this syntax for accessing dict … Read more

Import a Python module into a Jinja template?

Within the template, no, you cannot import python code. The way to do this is to register the function as a jinja2 custom filter, like this: In your python file: from dates.format import timesince environment = jinja2.Environment(whatever) environment.filters[‘timesince’] = timesince # render template here In your template: {% macro time(mytime) %} <a title=”{{ mytime }}”>{{ … Read more