replace a line in remote file

89 views
Skip to first unread message

vinay....@gmail.com

unread,
Feb 26, 2015, 5:24:06 PM2/26/15
to ansible...@googlegroups.com
Question:
Need some advice on how to do in ansible.

We are fetching the archive from artifactory url and calling a script to deploy the application.
The archive would be different for different release and we need to replace the value into the property file before executing the script.
In simpler words

Example for artifactory uri
http://xxxxxxxxx/artifactory/simple/internal-releases/xx/xxx/xx/ear/ZZZZ_EAR/0.0.4/ZZZZ_EAR-0.0.4.ear

we need to extract ZZZZ_EAR-0.0.4.ear

and then replace in /a/b/propFile/deployment.ini

from
DEPLOYMENTFILE=/x/yZZZZ/_EAR-0.0.4.ear
to
DEPLOYMENTFILE=/x/y/ZZZZ_EAR-0.0.4.ear
&
then finally excute the deploymentApplication.sh file


Need help with completing below ansible playbook for above requirement.

---
- name: Download WAR file from Artifactory
  get_url: url={{ artifactory_url }} dest={{ deploy_dir }} owner={{app_user}} group={{app_group}} mode=755
- name: extract deployment version
  shell: echo {{ artifactory_url }} | awk -F'[/]' '{print $13}'


<<<

replace line in /a/b/propFile/deployment.ini

from
DEPLOYMENTFILE=/x/yZZZZ/_EAR-0.0.1.ear
to
DEPLOYMENTFILE=/x/y/ZZZZ_EAR-0.0.4.ear
&

>>

- name: Deploy the application
  shell: chdir={{deploy_script}} ./deployApplication.sh

vinay....@gmail.com

unread,
Feb 26, 2015, 5:29:42 PM2/26/15
to ansible...@googlegroups.com


Correction of typo...

==

Question:
Need some advice on how to do in ansible.

We are fetching the archive from artifactory url and calling a script to deploy the application.
The archive would be different for different release and we need to replace the value into the property file before executing the script.
In simpler words

Example for artifactory uri
http://xxxxxxxxx/artifactory/simple/internal-releases/xx/xxx/xx/ear/ZZZZ_EAR/0.0.4/ZZZZ_EAR-0.0.4.ear

we need to extract ZZZZ_EAR-0.0.4.ear

and then replace in /a/b/propFile/deployment.ini

   from
DEPLOYMENTFILE=/x/y/ZZZZ_EAR-0.0.1.ear
to
DEPLOYMENTFILE=/x/y/ZZZZ_EAR-0.0.4.ear

then finally excute the deploymentApplication.sh file


Need help with completing below ansible playbook for above requirement.

---
- name: Download WAR file from Artifactory
  get_url: url={{ artifactory_url }} dest={{ deploy_dir }} owner={{app_user}} group={{app_group}} mode=755
- name: extract deployment version
  shell: echo {{ artifactory_url }} | awk -F'[/]' '{print $13}'


<<<

replace line in /a/b/propFile/deployment.ini

from
DEPLOYMENTFILE=/x/y/ZZZZ_EAR-0.0.1.ear
to
DEPLOYMENTFILE=/x/y/ZZZZ_EAR-0.0.4.ear

Edgars

unread,
Feb 27, 2015, 8:53:29 AM2/27/15
to ansible...@googlegroups.com
Hi

You can use lineinfile module http://docs.ansible.com/lineinfile_module.html but if I were you I would just download deployment file as ZZZ_EAR-latest.ear and in your config file it will always be DEPLOYMENTFILE=/x/y/ZZZZ_EAR-latest.ear

Edgars

Dan Vaida

unread,
Mar 5, 2015, 4:05:25 PM3/5/15
to ansible...@googlegroups.com
Funny to see how the lineinfile module gets all the fame when sometimes the replace module would be "good enough" http://docs.ansible.com/replace_module.html :)
Reply all
Reply to author
Forward
0 new messages