Depending on the number of values configured on a <multi/> node the return format inside get_config_dict() changes from string to list.
Assume the following:
ssh {
listen-address 172.18.254.201
port 22
port 2222
}This will yield: {'listen_address': '172.18.254.201', 'port': ['22', '2222']}
ssh {
listen-address 172.18.254.201
listen-address 172.18.254.202
port 22
port 2222
}This will yield: {['listen_address': '172.18.254.201', 'listen_address': '172.18.254.201'], 'port': ['22', '2222']}
Thus using this code for templating becomes error prone and will add a lot of redundancy to the templates. It can be coded as:
{% if listen_address %}
# Specifies the local addresses sshd should listen on
{% if listen_address is string %}
ListenAddress {{ listen_address }}
{% else %}
{% for address in listen_address %}
ListenAddress {{ value }}
{% endfor %}
{% endif %}
{% endif %}But is it would always return a list for a multi node (as what happens on conf.return_values()) the template will shrink to (and be consistent to return_values()):
{% if listen_address %}
# Specifies the local addresses sshd should listen on
{% for address in listen_address %}
ListenAddress {{ value }}
{% endfor %}
{% endif %}TagNodes
It turned out that this also becomes an issue on tag nodes.
Interface with one IP address
>>> Config().get_config_dict(['interfaces', 'ethernet', 'eth2', 'address'])
{'address': '2.2.2.2/32'}Interface with two IP addresses
>>> Config().get_config_dict(['interfaces', 'ethernet', 'eth1', 'address'])
{'address': ['fd00::ffff/64', '1.1.1.1/32']}In the past IP addresses have always been retrieved using return_values() which always ensured the result is a list. All subsequent code requires a list input here :(