|
只有找到的最后一行将被替换 backup:创建一个包含时间戳信息的备份文件
backrefs: 为no时,如果没有匹配,则添加一行line。如果匹配了,则把匹配内容替被换为line内容。
为yes时,如果没有匹配,则文件保持不变。如果匹配了,把匹配内容替被换为line内容。
insertafter:配合state=present。该行将在指定正则表达式的最后一个匹配之后插入。一个特殊的价值是在EOF; EOF用于在文件的末尾插入行。如果指定的正则表达式没有匹配,则将使用EOF
insertBefore:state=present。该行将在指定正则表达式的最后一个匹配之前插入。 BOF用于在文件的开头插入行。如果指定的正则表达式不匹配,则该行将被插入到文件的末尾。不能使用backrefs
valiate:在保存sudoers文件前,验证语法,如果有错,执行时,会报出来,重新编辑playbook
regexp: 正则表达式
# Before 2.3, option 'dest', 'destfile' or 'name' was used instead of 'path'
- lineinfile:
path: /etc/selinux/config
regexp: '^SELINUX='
line: 'SELINUX=enforcing'
- lineinfile:
path: /etc/sudoers
state: absent
regexp: '^%wheel'
- lineinfile:
path: /etc/hosts
regexp: '^127\.0\.0\.1'
line: '127.0.0.1 localhost'
owner: root
group: root
mode: 0644
- lineinfile:
path: /etc/httpd/conf/httpd.conf
regexp: '^Listen '
insertafter: '^#Listen '
line: 'Listen 8080'
- lineinfile:
path: /etc/services
regexp: '^# port for http'
insertbefore: '^www.*80/tcp'
line: '# port for http by default'
# Add a line to a file if it does not exist, without passing regexp
- lineinfile:
path: /tmp/testfile
line: '192.168.1.99 foo.lab.net foo'
# Fully quoted because of the ': ' on the line. See the Gotchas in the YAML docs.
- lineinfile:
path: /etc/sudoers
state: present
regexp: '^%wheel\s'
line: '%wheel ALL=(ALL) NOPASSWD: ALL'
# Yaml requires escaping backslashes in double quotes but not in single quotes
- lineinfile:
path: /opt/jboss-as/bin/standalone.conf
regexp: '^(.*)Xms(\\d+)m(.*)$'
line: '\1Xms${xms}m\3'
backrefs: yes
# Validate the sudoers file before saving
- lineinfile:
path: /etc/sudoers
state: present
regexp: '^%ADMIN ALL='
line: '%ADMIN ALL=(ALL) NOPASSWD: ALL'
validate: '/usr/sbin/visudo -cf %s' |
|
|