如何用 help blockinfile 替换块文本?
How to replace block text with help blockinfile?
我需要替换文件中的块文本。它:
passwd: compat
group: compat
shadow: compat
作者:
passwd: compat ldap
group: compat ldap
shadow: compat ldap
我不知道该怎么做。我读了 man blockinfile,但不知道如何替换文本:
- name: Update /etc/nsswitch.conf
blockinfile:
dest: /etc/nsswitch.conf
marker: ""
block: |
passwd: compat
group: compat
shadow: compat
请帮忙
我会使用 lineinfile:
- name: Update /etc/nsswitch.conf
lineinfile: dest=/etc/nsswitch.conf regexp="{{ item.regexp }}" line="{{ item.line }}"
with_items:
- { regexp: '^passwd:.*compat', line: 'passwd: compat ldap' }
- { regexp: '^group:.*compat', line: 'group: compat ldap' }
- { regexp: '^shadow:.*compat', line: 'shadow: compat ldap' }
我需要替换文件中的块文本。它:
passwd: compat
group: compat
shadow: compat
作者:
passwd: compat ldap
group: compat ldap
shadow: compat ldap
我不知道该怎么做。我读了 man blockinfile,但不知道如何替换文本:
- name: Update /etc/nsswitch.conf
blockinfile:
dest: /etc/nsswitch.conf
marker: ""
block: |
passwd: compat
group: compat
shadow: compat
请帮忙
我会使用 lineinfile:
- name: Update /etc/nsswitch.conf
lineinfile: dest=/etc/nsswitch.conf regexp="{{ item.regexp }}" line="{{ item.line }}"
with_items:
- { regexp: '^passwd:.*compat', line: 'passwd: compat ldap' }
- { regexp: '^group:.*compat', line: 'group: compat ldap' }
- { regexp: '^shadow:.*compat', line: 'shadow: compat ldap' }