I need to replace multiple configuration lines from one file using ansible. For this, I have used lineinfile module with regexp.
The play looks like this:
- name: Changing parameters in {{ rt_2_dir }}/config.xml
lineinfile:
path: "{{ ais_dir }}/Instances/{{ rt_2_dir }}/config.xml"
regexp: '{{item.From}}'
line: '{{item.To}}'
state: present
with_items:
- { From: ' <Configuration_Entry Key="Java Max Heap Size (MB)" Value="4096"/>', To: ' <Configuration_Entry Key="Java Max Heap Size (MB)" Value="16384"/>' }
- { From: ' <Configuration_Entry Key="Maximum number of queue listener threads (dialogs)" Value="20"/>', To: ' <Configuration_Entry Key="Maximum number of queue listener threads (dialogs)" Value="60"/>' }
- { From: ' <Configuration_Entry Key="Additional JVM Settings" Value="-Xms512M;-Xss256K;-XX:+UseConcMarkSweepGC;-XX:+UseTLAB;-Xrs"/>', To: ' <Configuration_Entry Key="Additional JVM Settings" Value="-Xms8192M;-Xss1024K;-XX:+UseParallelGC;-XX:+UseCMSInitiatingOccupancyOnly;-XX:CMSInitiatingOccupancyFraction=80;-XX:+UseTLAB;-Xrs;-Dorg.apache.activemq.SERIALIZABLE_PACKAGES=*;-XX:-UseGCLogFileRotation;-XX:GCLogFileSize=8M;-XX:-PrintGCTimeStamps;-verbose:gc;-Xloggc:/path/to/server/instance/logs/gclog.out;"/>' }
However, when running the the play, instead of replacing the lines, it adds the information at the end of the config file.
If I am replacing this 3 lines with the one below, it replaces it.
- { From: ' <Configuration_Entry Key="Add-On - Enable Geographic Add-On" Value="0"/>', To: ' <Configuration_Entry Key="Add-On - Enable Geographic Add-On" Value="1"/>' }
- { From: ' <Configuration_Entry Key="Add-On - Enable Financial Institutions" Value="0"/>', To: ' <Configuration_Entry Key="Add-On - Enable Financial Institutions" Value="1"/>' }
- { From: ' <Configuration_Entry Key="Add-On - Enable IP Enrichment" Value="0"/>', To: ' <Configuration_Entry Key="Add-On - Enable IP Enrichment" Value="1"/>' }
First I thought that there might be an issue with the parameters that are written at From:, thinking that they might not be identical in the config file, but when I looked in the config file, they exist and I have even copied the values from the config file as they were.
I am starting to think that some characters such as minus, semicolon, plus might be the issue here, because other lines are not getting impacted if there are no characters like these in From:.
Can someone help me adjust the code a bit so that these 3 lines get replaced properly?
Thank you!
search_string
in place ofregexp
? Since you seem to want to search using a fixed string (not a regular expression), it would make more sense to usesearch_string
.