gpt4 book ai didi

linux - 无法使用 Ansible 更新 sshd 配置文件

转载 作者:太空宇宙 更新时间:2023-11-04 05:11:24 25 4
gpt4 key购买 nike

我已按照帖子上发布的解决方案进行操作 Ansible to update sshd config file但是我收到以下错误。

TASK [Add Group to AllowGroups] 
fatal: [testpsr]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (lineinfile) module: when Supported parameters include: attributes, backrefs, backup, content, create, delimiter, directory_mode, firstmatch, follow, force, group, insertafter, insertbefore, line, mode, owner, path, regexp, remote_src, selevel, serole, setype, seuser, src, state, unsafe_writes, validate"}

Here are the tasks I have.
- name: Capture AllowUsers from sshd_config
command: bash -c "grep '^AllowUsers' /etc/ssh/sshd_config.bak"
register: old_userlist changed_when: no

- name: Add Group to AllowUsers
lineinfile: regexp: "^AllowUsers"
backup: True
dest: /etc/ssh/sshd_config.bak
line: "{{ old_userlist.stdout }} {{ usernames }}"
when: - old_userlist is succeeded

最佳答案

错误告诉您出了什么问题。

FAILED! => {"changed": false, "msg": "Unsupported parameters for (lineinfile) module: when

您将 when 嵌套在 lineinfile 模块下,而它应该嵌套在任务本身下。

这是您修复的代码,可能就是您的意思。

- name: Capture AllowUsers from sshd_config 
command: "grep '^AllowUsers' /etc/ssh/sshd_config.bak"
register: old_userlist
changed_when: no

- name: Add Group to AllowUsers
lineinfile:
regexp: "^AllowUsers"
backup: yes
dest: /etc/ssh/sshd_config.bak
line: "{{ old_userlist.stdout }} {{ usernames }}"
when: old_userlist is succeeded

我还修复了一些问题。在 command 中使用 bash -c 在您的情况下是多余的

在 StackOverflow 上粘贴代码或登录时,请确保您使用代码格式,因为您的问题当前无法读取。

关于linux - 无法使用 Ansible 更新 sshd 配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54888566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com