3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ansibleのlineinfileモジュールで該当行を削除

Last updated at Posted at 2018-07-12

ansibleでファイルの特定の行を置き換えたい場合、
replace or lineinfile or blockinfile を使うと思いますが、
regexpで該当した行の削除を改行コード込みで行いたいと思い調べてみました。

結論

lineinfile モジュールの state=absent を使えば行削除できるようです。
https://docs.ansible.com/ansible/2.5/modules/lineinfile_module.html

設定例

- name: Delete Line
  lineinfile:
    dest: '/path/to/file'
    regexp: 'deleteしたい箇所'
    state: absent
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?