【发布时间】:2021-03-21 12:03:07
【问题描述】:
我正在尝试制作正确处理 sshd_config 的 ansible 任务。我从其他问题中找到了类似的正则表达式,但它们什么也没做。
name: Disable SSH password authentication
become: true
lineinfile:
dest: /etc/ssh/sshd_config
regexp: '^#?\s*PasswordAuthentication\s'
line: 'PasswordAuthentication no'
state: present
问题是它应该处理重复的车道以及 cmets。例如:
- 可能有:
PasswordAuthentication no
PasswordAuthentication yes
或
PasswordAuthentication no
PasswordAuthentication no
或
PasswordAuthentication yes
PasswordAuthentication yes
或
PasswordAuthentication no
#PasswordAuthentication no
或
PasswordAuthentication no
# PasswordAuthentication no
或
# PasswordAuthentication no
# PasswordAuthentication no
等等这么多的组合。但我只想有一条未注释的行PasswordAuthentication no
这可能吗?
【问题讨论】:
-
对我来说,这听起来像是以所需状态部署文件,或者,如果必须进行自定义,使用 jinja 模板进行部署文件处于所需状态。对个别线路进行破解很少会导致最佳解决方案。
标签: linux shell ansible openssh