Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible lineinfile insertafter injects line at end of file

I'm using lineinfile as follows:

lineinfile dest=./hosts_exp insertafter='\[hosts1\]' line="xxxxxxxxx" state=present

My hosts_exp is as follows:

[local]
localhost

[hosts1]

[hosts2]

[hosts3]

lineinfile inserts the text after [hosts3] instead of inserting it after [hosts1].

like image 697
theharshest Avatar asked Jun 11 '14 21:06

theharshest


1 Answers

use:

lineinfile:
  dest: "./hosts_exp"
  line: "xxxxxxxxx"
  insertafter: '^\[hosts1\]'
  state: present
like image 69
fkoessler Avatar answered Oct 10 '22 20:10

fkoessler