# blockinfile no longer works in 2.1.0 (maybe eariler version, too)

**URL:** <https://forum.ansible.com/t/blockinfile-no-longer-works-in-2-1-0-maybe-eariler-version-too/21610>\
**Category:** Ansible Project\
**Created:** [May 31, 2016, 2:19pm UTC](https://forum.ansible.com/t/blockinfile-no-longer-works-in-2-1-0-maybe-eariler-version-too/21610 "2016-05-31T14:19:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scott\_Worthington](https://avatars.discourse-cdn.com/v4/letter/s/ac8455/32.png) [@Scott\_Worthington](https://forum.ansible.com/u/Scott_Worthington)\
**Post date:** [May 31, 2016, 2:19pm UTC](https://forum.ansible.com/t/blockinfile-no-longer-works-in-2-1-0-maybe-eariler-version-too/21610/1 "2016-05-31T14:19:03Z")

</div>

Hello,

I’m testing `ansible 2.1.0.0 built from the git repo.`  
`The actual installed RPM package on CentOS 7.2.1511 is ``ansible-2.1.0.0-0.git201605271344.2452bd2.stable21.el7.centos.noarch`

`I'm trying to use blockinfile.`

`My basic playbook named test-blockinfile.yml has:`

```auto
---
- hosts: localhost
  connection: local
  gather_facts: no

  tasks:

  - name: A very simple blockinfile test
    blockinfile:
      dest: ~/testfile
      insertbefore: BOF
      block: |
        This is my block
        This should work
        It is very basic test
      create: yes

```

Executing it with ansible-playbook -vvv test-blockinfile.yml results in:

```auto
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_lq3WNb/ansible_module_blockinfile.py", line 311, in <module>
    main()
  File "/tmp/ansible_lq3WNb/ansible_module_blockinfile.py", line 247, in main
    if module.constants['ANSIBLE_VERSION'].startswith('1.'):
AttributeError: 'AnsibleModule' object has no attribute 'constants'

Can anyone else confirm that they are getting the error, too?

I've submitted 2348: https://github.com/ansible/ansible-modules-extras/issues/2348

Thank you.

```

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [May 31, 2016, 2:48pm UTC](https://forum.ansible.com/t/blockinfile-no-longer-works-in-2-1-0-maybe-eariler-version-too/21610/2 "2016-05-31T14:48:21Z")

</div>

Your playbook is working for me on Kubuntu 16.04 and  
ansible 2.1.0.0 (detached HEAD 2452bd2135)  
&nbsp;&nbsp;&nbsp;lib/ansible/modules/core: (detached HEAD 21ef499e04)  
&nbsp;&nbsp;&nbsp;lib/ansible/modules/extras: (detached HEAD b19948181d)

---

<div class="post-metadata">

**Author:** ![Scott\_Worthington](https://avatars.discourse-cdn.com/v4/letter/s/ac8455/32.png) [@Scott\_Worthington](https://forum.ansible.com/u/Scott_Worthington)\
**Post date:** [June 5, 2016, 1:39pm UTC](https://forum.ansible.com/t/blockinfile-no-longer-works-in-2-1-0-maybe-eariler-version-too/21610/3 "2016-06-05T13:39:03Z")

</div>

I pulled down ansible via git repository to create an RPM via:

$ git clone git://github.com/ansible/ansible.git --recursive  
$ cd ./ansible  
$ git pull --rebase

However, I did not do the following:

$ git submodule update --init --recursive

> From the section [http://docs.ansible.com/ansible/intro\_installation.html#running-from-source:](http://docs.ansible.com/ansible/intro_installation.html#running-from-source:)

"Note when updating ansible, be sure to not only update the source tree,  
but also the “submodules” in git which point at Ansible’s own modules  
(not the same kind of modules, alas)."

After performing the above, then building and installing the RPM, the blockinfile module works.

$ make rpm  
$ sudo rpm -Uvh ./rpm-build/ansible-\*.noarch.rpm

Hopefully this helps someone else, too.
