ansible-collections / community.windows

Windows community collection for Ansible
https://galaxy.ansible.com/community/windows
GNU General Public License v3.0
198 stars 153 forks source link

Unexpected string added when using community.windows.win_xml #470

Open sefalbe opened 1 year ago

sefalbe commented 1 year ago
SUMMARY

I'm working with ansible to replace some values in web.config file, I'm using community.windows.win_xml module.

As you can see, I use EntityConn variable to set value:

vars:
  EntityConn: 'metadata=res://*/Northwind.csdl|res://*/Northwind.ssdl|res://*/Northwind.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\sqlexpress;Initial Catalog=Northwind;Integrated Security=True;MultipleActiveResultSets=True"'

The winxml module works but adds amp_ word when find &quot having as result &quot, and the final output:

<add name="EntityConn" connectionString="metadata=res://*/Northwind.csdl|res://*/Northwind.ssdl|res://*/Northwind.msl;provider=System.Data.SqlClient;provider connection string=&amp;quot;Data Source=.\sqlexpress;Initial Catalog=Northwind;Integrated 
Security=True;MultipleActiveResultSets=True&amp;quot" providerName="System.Data.EntityClient" />
ISSUE TYPE
COMPONENT NAME

community.windows.win_xml

ANSIBLE VERSION
ansible [core 2.13.7]
COLLECTION VERSION
# /usr/lib/python3/dist-packages/ansible_collections
Collection        Version
----------------- -------
community.windows 1.10.0

# /home/user/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.windows 1.11.1

# /usr/local/lib/python3.8/dist-packages/ansible_collections
Collection        Version
----------------- -------
community.windows 1.11.1
OS / ENVIRONMENT

Linux 4ansible 5.4.0-132-generic #148-Ubuntu SMP Mon Oct 17 16:02:06 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

STEPS TO REPRODUCE

- name: Windows Feature
  hosts: Windows2016
  vars:
    web_projects_path: "C:\\Path\\To\\Project"
    EntityConn: 'metadata=res://*/Northwind.csdl|res://*/Northwind.ssdl|res://*/Northwind.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\sqlexpress;Initial Catalog=Northwind;Integrated Security=True;MultipleActiveResultSets=True&quot;'

  tasks:
    - name: Print values
      ansible.builtin.debug:
        msg: MMSPRP5Entities {{ EntityConn}}

    - name: Change webconfig value
      community.windows.win_xml:
        path: "{{ web_projects_path }}\\Web.config"
        xpath: //configuration/connectionStrings/add[@name="EntityConn"]
        attribute: connectionString
        fragment: '{{ EntityConn }}'
        type: attribute
        state: present

And here my Web.config file:

<configuration>
  <connectionStrings>
    <add name="EntityConn" connectionString="" providerName="System.Data.EntityClient"/>
  </connectionStrings>
</configuration>
EXPECTED RESULTS

The expected result is the connection string without amp string

<configuration>
  <connectionStrings>
    <add name="EntityConn" connectionString="metadata=res://*/Northwind.csdl|res://*/Northwind.ssdl|res://*/Northwind.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\sqlexpress;Initial Catalog=Northwind;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient"/>
  </connectionStrings>
</configuration>
ACTUAL RESULTS
<configuration>
  <connectionStrings>
    <add name="EntityConn" connectionString="metadata=res://*/Northwind.csdl|res://*/Northwind.ssdl|res://*/Northwind.msl;provider=System.Data.SqlClient;provider connection string=&amp;quot;Data Source=.\sqlexpress;Initial Catalog=Northwind;Integrated 
Security=True;MultipleActiveResultSets=True&amp;quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>