Score:0

Write original Ansible variable to xml file

br flag

I'm trying to find a way to write the original {{ ansible_host }} var in to a xml file. This variable will replace a static IP in a device config. The reason that I want to replace this IP with the original variable in the file, is because later in my playbook that variable gives me the option to make the file compatible with multiple devices.

What I have:

- name: Replace static ip in config file to Ansible variable
  xml:
    path: '{{ backup_folder }}{{ inventory_hostname }}.xml'
    xpath: /config/devices/entry/deviceconfig/system/ip-address
    value: "{{ ansible_host }}"
    state: present

Result (in file):

      <ip-address>10.0.89.103</ip-address>

What it needs to be:

      <ip-address>{{ ansible_host }}</ip-address>

Does anyone know how to do this? Thanks

Score:1
in flag

From this answer on SO:

value: "{{ '{{ ansible_host }}' }}"
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.