I know we can use blockinfile in Ansible 2. Is there any way to achieve same in Ansible 1.9
Have you considered lineinfile?
I considered it, But It doesn’t work when I add multiple group to sshd_config file. For ex for below configuration lineinfile updates at same line for another group as well
- name: SFTP-Server | Add sshd_config block
lineinfile:
dest: /etc/ssh/sshd_config
line: “{{ item.line }}”
insertafter: “{{ item.insertafter }}”
with_items: - { line: “Match Group {{ sftp_group_name }}”, insertafter: “EOF” }
- { line: " PasswordAuthentication yes", insertafter: ‘Match Group {{ sftp_group_name }}’ }
- { line: " ForceCommand internal-sftp {{ sftp_enable_logging | ternary(‘-l VERBOSE’, ‘’) }}", insertafter: ‘Match Group {{ sftp_group_name }}’ }
- { line: " X11Forwarding no", insertafter: ‘Match Group {{ sftp_group_name }}’ }
- { line: " AllowTCPForwarding no", insertafter: ‘Match Group {{ sftp_group_name }}’ }
- { line: " ChrootDirectory %h", insertafter: ‘Match Group {{ sftp_group_name }}’ }
notify: SFTP-Server | Restart sshd
This sort of logic seems a little bit over the top for lineinfile.
What about using the template module?
Dick