此模块是针对文件特殊行,使用后端引用的正则表达式来替换。

- hosts: 192.168.50.1
  gather_facts: no
  tasks:
    - name: 设置UseDNS为no
        lineinfile:
          dest: /etc/ssh/sshd_config   # 需要修改的配置文件
          backrefs: yes                # 1.regexp匹配的话则替换成line 2.不匹配的话则添加line
          regexp: '^#UseDNS yes'       # 寻找以#UseDNS yes开头的行
          line: 'UseDNS no'            # 将regexp匹配到的行替换成line
    - name: 重启SSHD服务
        service: 
          name: sshd
          state: restarted

相关文章:

  • 2022-12-23
  • 2021-10-18
  • 2021-06-15
  • 2021-08-05
  • 2021-09-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
  • 2022-12-23
  • 2021-06-26
  • 2021-07-27
相关资源
相似解决方案