Ansible:在/ etc/ssh/sshd_config中将UseDNS设置为"no"

gue*_*tli 2 ansible

我想更新文件/etc/ssh/sshd_config并设置UseDNS no.

我想只更新这个值,而不是为整个文件使用模板.

是否有一种通用的方法来设置基于键值的配置(使用unix-config-style)和ansible?

Arb*_*zar 6

你可以使用lineinfile它的模块,像这样:

- 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
Run Code Online (Sandbox Code Playgroud)