J
J
juffinhalli2015-06-08 20:27:15
Python
juffinhalli, 2015-06-08 20:27:15

How to uncomment a complex line with Ansible?

Good afternoon!
Given:
file with three lines

--awful.util.spawn('sh -c "sleep 5s && one"')
--awful.util.spawn('sh -c "sleep 5s && two"')
--awful.util.spawn('sh -c "sleep 5s && three"')

Task
Uncomment (remove the first characters --) on the line containing two
My attempt:
- replace:
      dest=/home/{{ desktop_user }}/.config/awesome/rc.lua
      regexp="--awful.util.spawn(\"sh -c \"sleep 5s && two\"')"
      replace="awful.util.spawn(\"sh -c \"sleep 5s && two\"')"

playbook passes without changes
Please help in solving the problem.
Thanks in advance
PS Python don't know
PPS Read the documentation but understood too little.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2015-06-08
@juffinhalli

- replace:
      dest=/home/{{ desktop_user }}/.config/awesome/rc.lua
      regexp="\-\-awful\.util\.spawn\(\'sh\ \-c\ \"sleep\ 5s\ \&\&\ one\"\)"
      replace="awful.util.spawn('sh -c \"sleep 5s && two\"')"

such a line can be prepared like this
import re

print re.escape("""--awful.util.spawn('sh -c "sleep 5s && one")""")

# \-\-awful\.util\.spawn\(\'sh\ \-c\ \"sleep\ 5s\ \&\&\ one\"\)

Y
Yuri Shikanov, 2015-06-08
@dizballanze

It’s better to put such files into templates and it’s easy to implement any logic there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question