# Lineinfile append at EOF

**URL:** <https://forum.ansible.com/t/lineinfile-append-at-eof/21765>\
**Category:** Ansible Project\
**Created:** [June 14, 2016, 5:06am UTC](https://forum.ansible.com/t/lineinfile-append-at-eof/21765 "2016-06-14T05:06:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mona\_Gopal](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Mona\_Gopal](https://forum.ansible.com/u/Mona_Gopal)\
**Post date:** [June 14, 2016, 5:06am UTC](https://forum.ansible.com/t/lineinfile-append-at-eof/21765/1 "2016-06-14T05:06:32Z")

</div>

Hi all,

I am trying to use the lineinfile module to append some of the software details to a file.  
I don’t want to match to any regexp, but just insert every software details at the EOF.

Below is the piece of code.

- name: Collect python details  
action: get\_python\_details  
register: python

- name: Write registered variable to file  
local\_action: lineinfile dest={{ third\_party\_dest\_path }} line={{ python }} regexp=“” insertafter=EOF state=present create=yes

Have also tried giving regexp=“^$”, regexp=“^\s\*$” as well to match to an empty line, but throws the below error.

Error:

```auto
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/root/.ansible/tmp/ansible-tmp-1465888759.41-82910653497853/lineinfile", line 2540, in <module>
    main()
  File "/root/.ansible/tmp/ansible-tmp-1465888759.41-82910653497853/lineinfile", line 371, in main
    ins_aft, ins_bef, create, backup, backrefs)
  File "/root/.ansible/tmp/ansible-tmp-1465888759.41-82910653497853/lineinfile", line 266, in present
    lines.append(line + os.linesep)
TypeError: unsupported operand type(s) for +: 'dict' and 'str'

fatal: [172.19.3.60 -> localhost]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_name": "lineinfile"}, "parsed": false}

```

```auto

```

```auto
Kindly help on how to go about appending to EOF without matching to any regexp.

```

```auto

```

```auto
Thanks in advance,

```

```auto
Mona G

```

---

<div class="post-metadata">

**Author:** ![Mona\_Gopal](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Mona\_Gopal](https://forum.ansible.com/u/Mona_Gopal)\
**Post date:** [June 14, 2016, 6:12am UTC](https://forum.ansible.com/t/lineinfile-append-at-eof/21765/2 "2016-06-14T06:12:29Z")

</div>

Hi All,

I figured out that the below works to append to a file,

- name: Write redis details to file  
local\_action: lineinfile dest={{ third\_party\_dest\_path }} line=redis state=present create=yes

However, i am unable to append the registered variable value to the file

- name: Write redis details to file  
local\_action: lineinfile dest={{ third\_party\_dest\_path }} **line=“{{ redis }}”** state=present create=yes

---

<div class="post-metadata">

**Author:** ![Jason3](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@Jason3](https://forum.ansible.com/u/Jason3)\
**Post date:** [June 14, 2016, 2:07pm UTC](https://forum.ansible.com/t/lineinfile-append-at-eof/21765/3 "2016-06-14T14:07:55Z")

</div>

Mona, I don’t think you need the regexp parameter, just set ‘insertafter: EOF’ to get it to append at the end of the file. See for what works for me in one of my scripts:

- name: add script exec to bashrc  
lineinfile:  
dest: /home/.bashrc  
state: present  
line: ‘. /home/.profile-custom’  
insertafter: EOF

---

<div class="post-metadata">

**Author:** ![Abhishek\_R](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@Abhishek\_R](https://forum.ansible.com/u/Abhishek_R)\
**Post date:** [June 15, 2016, 12:01pm UTC](https://forum.ansible.com/t/lineinfile-append-at-eof/21765/4 "2016-06-15T12:01:47Z")

</div>

You should probably try using {{ redis.stdout }}. Registered variables are not inherently strings, unlike extra\_vars.

Regards
