Ansible - 检查 PermitRootLogin 是否等于 no

Ansible - Check if PermitRootLogin is equal to no

我是 Ansible 新手

想知道/etc/ssh/中PermitRootLogin=no的值是不是sshd_config

- hosts: RH7
  tasks:

  - name: read File
    shell: cat /etc/ssh/sshd_config
    register: PermitRootLogin no

请帮帮我

你可以这样使用:

- hosts: RH7
  tasks:

  - name: read File
    shell: awk '/#PermitRootLogin/ {print }' /etc/ssh/sshd_config
    register: PermitRootLogin

  - debug: msg="{{ PermitRootLogin.stdout }}"

cat /etc/ssh/sshd_config | awk '/#PermitRootLogin/ {print }' :此命令将为您提供文件 /etc/ssh/sshd_config.

中 PermitRootLogin 的输出

我们会将值保存在 PermitRootLogin 变量中,可以使用 debug 命令查看它。