Ansible remove comment above specific line - ansible

I am doing a script to automate file editing on server when deploying an agent of some service, the file is config.xml and I am editing fields using replace, so for eg.:
- name: Update config.xml - PROXY HOST
replace:
path: "{{agent_path}}{{ cfg_agent }}/agent/config.xml"
regexp: "YOUR_PROXY_HOST"
replace: "{{cfg_proxyhost}}"
Config.xml looks like:
<!--
<parameter name="mid.proxy.use_proxy" value="true"/>
<parameter name="mid.proxy.host" value="YOUR_PROXY_HOST"/>
<parameter name="mid.proxy.port" value="YOUR_PROXY_PORT"/>
-->
So when I run this particular task it will replace YOUR_PROXY_HOST for a value under {{cfg_proxyhost}}, let's say like that:
<!--
<parameter name="mid.proxy.use_proxy" value="true"/>
<parameter name="mid.proxy.host" value="http://proxy.foo"/>
<parameter name="mid.proxy.port" value="YOUR_PROXY_PORT"/>
-->
But then I need to remove those <!-- above and --> below to make it working.
There is a lot of other parameters in the file commented in the same way.
I need to remove these particular ones.
How can it be done using ansible?

Actually I have resolved it by using Jinja2 template, replacing the files with a pre-defined variables within a template, but if any of You could answer how to just remove that comment, that will be nice :)

Related

Environment variables in ROS YAML file?

Is there a way to use environment variables in a ROS yaml file that gets loaded during a launch file?
For example,
test.launch:
<launch>
<rosparam command="load" file="example.yaml" />
</launch>
example.yaml:
vehicle_name: "${VEHICLE_NAME}_robot"
I know that you could load the environment variable as a param in the launch file using the <env> or <optenv> tags, but when there are a lot of parameters, it's much neater to have them defined in a separate .yaml file. Is there a recommended way to do this?
The rosparam tag has an attribute subst_value to enable the env, optenv, etc. substitution args for the YAML text when added directly in the launch file. That is the following works:
<launch>
<!-- works -->
<rosparam subst_value="true">
foo: $(env USER)
</rosparam>
</launch>
For ROS Kinetic and later, it also works when using an external YAML file:
<launch>
<rosparam file="/path/to/conf.yaml" subst_value="true" />
</launch>
No, roslaunch just uses PyYAML's .load and PyYaml does not support reading env variables in yaml files.
You could create multiple yaml files different names and load them selectively using env variables in launch files, for example:
<launch>
<rosparam command="load" file="$(optenv VEHICLE_NAME default_vehicle_name)_example.yaml" />
</launch>
`

Configuring Spring batch xml

Issue: Using spring batch, i need to read a file which has todays date. E.g test_02032015.txt.This file will be in a directory /test/example. Its an unix environment that i need to fetch file from.
question is how to configure spring batch xml so that above mentioned file is read
Any pointers to relevant website or solution would be of great help.
You have a few ways to address a requirement like this:
If you don't need to worry about the other files in a directory, you can just use a wild card in the file name like this:
<property name="resource" value="data/iosample/input/*.xml" />
Another alternative would be to pass the value into the job as a parameter and reference it like this:
<property name="resource" value="#{jobParameters['input.file']}" />
Finally you could use SpEL to build the file name (Sorry I don't have an example of that handy).

WIX public properties displayed on the UI

We have an installer created using WIX. As part of this install we would like to show the currently selected installation path. I thought this would be much easier than it is, apparently. I have tried using the a public property "INSTALLDIR" (I know we're not using Installshield, this value is a directory ID.)
<Directory Id="INSTALLDIR" Name="AcmeInc">
I can also see where INSTALLDIR gets set when running the install
MSI(EC:6C) Dir (target): Key: INSTALLDIR , Object: C:\Program Files\AcmeInc\
but when I try to show this on the UI using a Text attribute I get "...\." which doesn't even look to be a relative path.
I know there has got to be something simple I'm missing here.
Assuming you're using WiX 3.5 and the MajorUpgrade element - the following should work (I usually use APPLICATIONFOLDER instead of INSTALLDIR - but they should be interchangeable).
First, let's set ARPINSTALLOCATION as described on http://robmensching.com/blog/posts/2011/1/14/ARPINSTALLLOCATION-and-how-to-set-it-with-the-WiX-toolset
<SetProperty Id="ARPINSTALLLOCATION" Value="[INSTALLDIR]" After="CostFinalize" />
Now lets set the selected installation folder to the previous installation folder, if one previously existed that is.
<Property Id="INSTALLDIR" Secure="yes">
<RegistrySearch Id="FindInstallLocation"
Root="HKLM"
Key="Software\Microsoft\Windows\CurrentVersion\Uninstall\[WIX_UPGRADE_DETECTED]"
Name="InstallLocation"
Type="raw"
Win64="yes" />
</Property>
And during the UI sequence, we want this value to be set 'early'
<InstallUISequence>
<AppSearch After="FindRelatedProducts"/>
</InstallUISequence>

vs2010 breaks the content of parameters.xml

I've got the file Parameters.xml that contains the following
<parameter name="Identity Suffix" description="Suffix of the identity services of the environment" tags="" >
<parameterEntry kind="TextFile" scope="\\web.config$" match="__IDENTITY_SUFFIX__"/>
<parameterValidation type="AllowEmpty" />
</parameter>
After I run Build deployment package the output file does not contains any parameterValidation and I have to edit the file manually. How to fix this behavior ?
IIS supports two schemes:
<parameterValidation kind="AllowEmpty" />
<parameterValidation type="AllowEmpty" />
VS supports only first one

Wix Conditionally Install Component if Registry Key Exists

I have a component I need to install only if a registry key exists which means an application has been installed.
I need to assign the value of the registry key (it is a directory) to a property then use this property to copy files from.
I have the following script so far but get an error "The system cannot find the file '[MYTESTDIR]fileToCopy.dat'."
Any help would really be appreciated.
<Property Id="MYTESTDIR">
<RegistrySearch Id="NetFramework20"
Root="HKLM"
Key="SOFTWARE\TEST\VALUE\1.00"
Name="MyName"
Type="directory" />
</Property>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="TEST" Name="Test">
<Component Id="MyComponent" Guid="E5FF53DE-1739-42c4-BE37-60F810C9CD69">
<Condition>MYTESTDIR</Condition>
<File Id="fileToCopy.dat" Name="fileToCopy.dat" Source="[MYTESTDIR]fileToCopy.dat">
<CopyFile Id="fileToCopy.datCopy" DestinationProperty="WEBSERVICEBINFOLDER" />
</File>
</Directory>
</Directory>
</Directory>
<Feature Id="MyFeature" Title="MyFeature" Level="1">
<ComponentRef Id="MyComponent" />
</Feature>
Based on my reading of the Wix Schema documentation, your problem is that you have the CopyFile element nested under a File element. Ditch the File element and just have the CopyFile sit under the Component:
<Component Id="MyComponent" Guid="E5FF53DE-1739-42c4-BE37-60F810C9CD69">
<Condition>MYTESTDIR</Condition>
<CopyFile Id="fileToCopy.datCopy" SourceName="[MYTESTDIR]fileToCopy.dat" DestinationProperty="WEBSERVICEBINFOLDER" />
</Component>
The way you had it, nested under the File, Wix was looking for the file on your system during the build - rather than setting up a copy command to be run at install time.
MYTESTDIR is a windows installer property which will get its value on the target system when the package is being installed.
However, you are trying to use this property in a Source attribute, which is used to point to files on the system where the setup package is being build.
Obviously that is not going to work. Windows installer properties don't even exist while the Source attribute is being evaluated, so Source can definitely not support such use.
Bryan's answer is the correct solution for what you're trying to do here. Using CopyFile under a File element is not illegal, but it is intended for copying files which you also install. In this case, you want to copy a file which is already on the target system, so the File element is not appropriate.

Resources