次のように lineinfile を使用しています。
lineinfile dest=./hosts_exp insertafter='\[hosts1\]' line="xxxxxxxxx" state=present
私のhosts_exp
は次のとおりです。
[local]
localhost
[hosts1]
[hosts2]
[hosts3]
lineinfile は、[hosts1] の後にテキストを挿入するのではなく、[hosts3] の後にテキストを挿入します。