What dashes mean 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

Remove the empty lines left by Jinja2 variable definitions

There is whitespace control in Jinja2. You might want: {%- set ip = grains[‘ip4_interfaces’][‘eth1’][0] -%} {%- set domain = pillar[‘company_domain’] -%} {%- set version = pillar[‘site_version’] -%} {%- set site_url=”www.” + domain -%} […] As well, the salt configuration file supports jinja_trim_blocks and jinja_lstrip_blocks (jinja_env:trim_blocks, jinja_env:lstrip_blocks, jinja_sls_env:trim_blocks, and jinja_sls_env:lstrip_blocks as of 2018.3).

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)