replace module issue

22 views
Skip to first unread message

visar

unread,
Nov 30, 2018, 5:45:06 AM11/30/18
to Ansible Project
tried to replace specific path in .conf file with another file using ansible but not getting modified as wanted.

below is my .conf file content

<!-- Server Clusters --><ServerCluster CloneSeparatorChange="false" GetDWLMTable="false" IgnoreAffinityRequests="true" LoadBalance="Round Robin" Name="Shared_3_Cluster_0" PostBufferSize="0" PostSizeLimit="-1" RemoveSpecialHeaders="true" RetryInterval="60" ServerIOTimeoutRetry="-1">
       
<Server CloneID="0577049b-9886-4e73-8717-1663b85204bb" ConnectTimeout="5" ExtendedHandshake="false" LoadBalanceWeight="20" MaxConnections="-1" Name="default_node_clm_2" ServerIOTimeout="900" WaitForContinue="false">
         
<Transport Hostname="MYSERVER1DNS" Port="9080" Protocol="http"/>
         
<Transport Hostname="MYSERVER1DNS" Port="9443" Protocol="https">
           
<Property Name="keyring" Value="/opt/IBM/WebSphere/Plugins/config/webserver1/plugin-key.kdb"/>
           
<Property Name="stashfile" Value="/opt/IBM/WebSphere/Plugins/config/webserver1/plugin-key.sth"/>
         
</Transport>
     
</Server>
       
<Server CloneID="a89c5825-ed68-4e64-88a3-af800e1c98aa" ConnectTimeout="5" ExtendedHandshake="false" LoadBalanceWeight="20" MaxConnections="-1" Name="default_node_clm_1" ServerIOTimeout="900" WaitForContinue="false">
         
<Transport Hostname="MYSERVER2DNS" Port="9080" Protocol="http"/>
         
<Transport Hostname="MYSERVER2DNS" Port="9443" Protocol="https">
           
<Property Name="keyring" Value="/opt/IBM/WebSphere/Plugins/config/webserver1/plugin-key.kdb"/>
           
<Property Name="stashfile" Value="/opt/IBM/WebSphere/Plugins/config/webserver1/plugin-key.sth"/>
         
</Transport>
     
</Server>
       
<Server CloneID="98e33a6f-822c-40b5-90a6-71b6747ed1bd" ConnectTimeout="5" ExtendedHandshake="false" LoadBalanceWeight="20" MaxConnections="-1" Name="default_node_clm_0" ServerIOTimeout="900" WaitForContinue="false">
         
<Transport Hostname="MYSERVER3DNS" Port="9080" Protocol="http"/>
         
<Transport Hostname="MYSERVER3DNS" Port="9443" Protocol="https">
           
<Property Name="keyring" Value="/opt/IBM/WebSphere/Plugins/config/webserver1/plugin-key.kdb"/>
           
<Property Name="stashfile" Value="/opt/IBM/WebSphere/Plugins/config/webserver1/plugin-key.sth"/>


           
Here I was trying to modify the repeating strings

From________________________________________________________________________________________________________________________
                  <Property Name="keyring" Value="/opt/IBM/WebSphere/Plugins/config/webserver1/plugin-key.kdb"/>
                 
<Property Name="stashfile" Value="/opt/IBM/WebSphere/Plugins/config/webserver1/plugin-key.sth"/>


                 
______________________________________________________________________________________________________________________________

To

                  <Property Name="keyring" Value="/opt/HTTPServer/key.kdb"/>
                 
<Property Name="stashfile" Value="/opt/HTTPServer/key.sth"/>


                 
_____________________________________________________________________________________________________________________________

Tried with my below play , its changing the value, but the spaces are not coming exactly as it neeed ( the modified line is just staring from the begining) and which is making application down

- name: change ihs plugin
  hosts
: IHS
  tasks
:
   
- name: Ansible replace string example
      replace
:
        path
: /opt/IBM/WebSphere/Plugins/config/WebServer1/Plugin-cfg.xml
        regexp
: '^(.*<Property Name="keyring" Value="/opt/IBM/WebSphere/Plugins/config/webserver1/plugin-key.kdb"/>.*)'
        replace
: '<Property Name="keyring" Value="/opt/IBM/HTTPServer/key.kdb"/>'
   
- name: Ansible replace string example
      replace
:
        path
: /opt/IBM/WebSphere/Plugins/config/WebServer1/Plugin-cfg.xml
        regexp
: '^(.*<Property Name="stashfile" Value="/opt/IBM/WebSphere/Plugins/config/webserver1/plugin-key.sth"/>.*)'
        replace
: '<Property Name="stashfile" Value="/opt/IBM/HTTPServer/key.sth"/>'




Also want to take backup of the file before making these changes and need to send a mail once the changes happened as expected with an attachment with this file.

tried this, but failed.

- name: Send email
     mail
:
        host
: smtpserver.com
        port
: 25
        username
: mydomainID
        password
: mypass
        subject
: "Ansible test mail"
        attach
: /opt/IBM/WebSphere/Plugins/config/WebServer1/Plugin-cfg.xml
        body
: "Testing email"
       
from: mymailid.com
        to
:
         
- mymailid.com
        charset
: utf8
        secure
: never


                 

visar

unread,
Dec 2, 2018, 2:37:08 AM12/2/18
to Ansible Project
Hello Experts,

Any suggestion here please...

Piotr Owcarz

unread,
Dec 3, 2018, 4:18:03 PM12/3/18
to ansible...@googlegroups.com
Hi Visar

As for the IHS plugin file modification try using the Ansible's xml module: https://docs.ansible.com/ansible/2.4/xml_module.html
As for the mail, you are writing, that  your playbook fails, but you don't send us any output. Run your playbook with -vvv and see what's wrong. Also, note, that ansible tasks manipulating files usually make backups automatically on every modification. Check the 'backup' parameter of the xml module.

Piotr

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6b254fa8-3f81-4c56-b4c0-d8d30d4a1122%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages