unable to delete line file

20 views
Skip to first unread message

Deepak Sharma

unread,
Mar 12, 2019, 3:00:08 PM3/12/19
to Ansible Project
this is my host file.

#  cat /tmp/node/test.new
[masters]
[nodes]
453.abc.com  openshift_node_labels,22,="{'region': 'us_midwest', 'datacenter': 'ctc', 'zone': 'core', 'environment': 'nonprod', 'logging-infra-fluentd': 'true'}"
678abc.com  openshift_node_labels,22,="{'region': 'us_midwest', 'datacenter': 'ctc', 'zone': 'core', 'environment': 'nonprod', 'logging-infra-fluentd': 'true'}"
#

and i want to delete 453.abc.com whole line from /tmp/node/test.new

with below syntax but getting error, can some one help me


lineinfile: dest=/tmp/node/test.new
              regexp='^{{ansible_hostname}}$'
              state=absent

but getting error

Deepak Sharma

unread,
Mar 12, 2019, 5:19:03 PM3/12/19
to Ansible Project
can someone help me..??

Jean-Yves LENHOF

unread,
Mar 12, 2019, 5:20:36 PM3/12/19
to ansible...@googlegroups.com

Provide error log

--
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/cbd53d0a-f87c-430f-ac5d-265837f08091%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sebastian Meyer

unread,
Mar 12, 2019, 6:02:55 PM3/12/19
to ansible...@googlegroups.com, Deepak Sharma
'^{{ ansible_hostname }}$' matches a line containing only the name of
the node currently running the task.

If you want to delete a line starting with the name of the node you'll
need '^{{ ansible_hostname }}', without the $ which means line end.

If you are getting an error, providing the error message would help ...

Regards
--
Sebastian Meyer
Linux Consultant & Trainer
Mail: me...@b1-systems.de

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537

Deepak Sharma

unread,
Mar 14, 2019, 4:01:02 AM3/14/19
to Ansible Project
it is working now,

with below syntax.

lineinfile: dest=/tmp/node/test.new
                  regexp='^{{ansible_hostname}}'
                  state=absent
      delegate_to: "{{ groups['masters'][0] }}"
      changed_when: False


On Wednesday, March 13, 2019 at 12:30:08 AM UTC+5:30, Deepak Sharma wrote:
Reply all
Reply to author
Forward
0 new messages