Ansible:将UseDNS设置为;否";在/etc/ssh/sshd\u config中

Ansible:将UseDNS设置为;否";在/etc/ssh/sshd\u config中,ansible,Ansible,我想更新文件/etc/ssh/sshd\u config并设置UseDNS no 我只想更新这个值,不想对整个文件使用模板 是否有一种通用方法可以使用ansible设置基于键值的配置(使用unix配置样式)?您可以使用lineinfle模块,如下所示: - name: Update the /etc/ssh/sshd_config file lineinfile: dest: /etc/ssh/sshd_config regexp: "^UseDNS" line: "

我想更新文件
/etc/ssh/sshd\u config
并设置
UseDNS no

我只想更新这个值,不想对整个文件使用模板


是否有一种通用方法可以使用ansible设置基于键值的配置(使用unix配置样式)?

您可以使用
lineinfle
模块,如下所示:

- name: Update the /etc/ssh/sshd_config file
  lineinfile:
    dest: /etc/ssh/sshd_config
    regexp: "^UseDNS"
    line: "UseDNS no"
    insertafter: EOF
    state: present
  register: ssh_config

- name: Restart ssh
  service:
    name: ssh
    state: restarted
  when: ssh_config.changed

有没有办法在文件更改后自动重新启动sshd?