Hi Ansible community,
I am observing syntax error on attempt to use Jinja2 control structures in the tasks file:
Code
/opt/ansible/roles/network/tasks/network.yml:
{% if publicavailable|default(False) == False and public|default(“”) == “” and datacenter != “XXX” and datacenter != “YYY” %}
{% set private_interface = ansible_default_ipv4.interface %}
{% else %}
{% set private_interface = ansible_default_ipv4.interface|regex_replace(‘\d+’,‘’)|string + (ansible_default_ipv4.interface|regex_replace(‘\D+’,‘’)|int+1)|string %}
{% endif %}
- name: alias interface on private servers
template:
src: if_internal_eth.j2
dest: /etc/network/interfaces.d/if_{{ private_interface }}_0.cfg
owner: root
group: root
mode: 0644
when: ‘datacenter != “XXX” and datacenter != “YYY” and vlan_prefix2|default(“”) != “”’
Error
fatal: [host.domain.tld]: FAILED! => {“reason”: "Syntax Error while loading YAML.
found character that cannot start any token
The error appears to have been in /opt/ansible/roles/network/tasks/network.yml: line 52, column 2, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:{% if publicavailable|default(False) == False and public|default("") == "" and datacenter != "XXX" and datacenter != "YYY" %}
^ here
"}
Versions
ansible 2.5.10
python version = 2.7.12
Ubuntu 16.04.3 LTS
Kindly advise!
Thank you,
Alex