-1

I have followed the solution posted on the post Ansible to update sshd config file however I am getting the following errors.

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
error404
  • 2,684
  • 2
  • 13
  • 21

1 Answers1

0

The error tells you whats wrong.

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

You nested when under lineinfile module, while it should be nested under the task itself.

This is your code fixed and probably what you meant.

- 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

I also fixed a couple of things. Using bash -c in command is redundant in your case

Please make sure you are using code formatting when pasting code or logs on StackOverflow, as your question is currently unreadable.

vane41
  • 378
  • 1
  • 2
  • 6
  • thanks for the edit vane41. It did work, however, the user got added as [u 'username']. – Parvinder Raheja Feb 26 '19 at 15:54
  • You should take a closer look on how you define `usernames`. This should point you in the right direction. https://stackoverflow.com/a/41521816/4794849 – vane41 Feb 26 '19 at 16:15
  • Thanks again for the pointer. Change the line: to the following and it worked.line: "{{ old_grouplist.stdout }} {{ ' '.join(usernames) }}" – Parvinder Raheja Feb 26 '19 at 16:23