ansible-playbook常用模块

一.lineinfile

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

- 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
原文地址:https://www.cnblogs.com/yuhaohao/p/13092237.html