Remove a line from file and surrounding

47 views
Skip to first unread message

Laci

unread,
Jun 14, 2022, 8:30:01 AM6/14/22
to Ansible Project
I'm working on a playbook which would remove lines from a file containing specific hostname.
I want to use Ansible to remove the hostname AND surrounding lines. Here is an example of a block that I need to remove:

FileSet {
Name = "vcenter-hostname05"
 Include {
   Options {
   signature = SHA1
   compression=GZIP
   noatime=yes
 }
Plugin = "vsphere: server=vsphere-vcenter host=hostname05.domain.com abort_on_error"
       }
}

Does anyone have a suggestion how would I match the lines when all I have is hostname05?

Laci

unread,
Jun 14, 2022, 10:59:38 AM6/14/22
to Ansible Project

So far my best option is to run a command which invokes sed

Jeff S

unread,
Jun 15, 2022, 7:37:01 AM6/15/22
to Ansible Project

Laci

unread,
Jun 21, 2022, 5:18:56 AM6/21/22
to Ansible Project
Thank you Jeff!
I ended up using a shell script with sed.

Reply all
Reply to author
Forward
0 new messages