# Alternative for blockinfile in Ansible 1.9

**URL:** <https://forum.ansible.com/t/alternative-for-blockinfile-in-ansible-1-9/24981>\
**Category:** Ansible Project\
**Created:** [July 14, 2017, 7:14am UTC](https://forum.ansible.com/t/alternative-for-blockinfile-in-ansible-1-9/24981 "2017-07-14T07:14:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Selvakumar\_Ponnusamy](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Selvakumar\_Ponnusamy](https://forum.ansible.com/u/Selvakumar_Ponnusamy)\
**Post date:** [July 14, 2017, 7:14am UTC](https://forum.ansible.com/t/alternative-for-blockinfile-in-ansible-1-9/24981/1 "2017-07-14T07:14:14Z")

</div>

I know we can use blockinfile in Ansible 2. Is there any way to achieve same in Ansible 1.9

---

<div class="post-metadata">

**Author:** ![Listing](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@Listing](https://forum.ansible.com/u/Listing)\
**Post date:** [July 14, 2017, 9:05am UTC](https://forum.ansible.com/t/alternative-for-blockinfile-in-ansible-1-9/24981/2 "2017-07-14T09:05:40Z")

</div>

Have you considered lineinfile?

---

<div class="post-metadata">

**Author:** ![Selvakumar\_Ponnusamy](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Selvakumar\_Ponnusamy](https://forum.ansible.com/u/Selvakumar_Ponnusamy)\
**Post date:** [July 17, 2017, 6:46am UTC](https://forum.ansible.com/t/alternative-for-blockinfile-in-ansible-1-9/24981/3 "2017-07-17T06:46:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [July 18, 2017, 7:48am UTC](https://forum.ansible.com/t/alternative-for-blockinfile-in-ansible-1-9/24981/4 "2017-07-18T07:48:38Z")

</div>

This sort of logic seems a little bit over the top for lineinfile.  
What about using the template module?

Dick
