{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/736","labels_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/736/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/736/comments","events_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/736/events","html_url":"https://github.com/ansible/ansible-modules-core/issues/736","id":56116878,"number":736,"title":"lineinfile function appends to last line if there is no trailing LF character","user":{"login":"miguelgrinberg","id":2715854,"avatar_url":"https://avatars.githubusercontent.com/u/2715854?v=3","gravatar_id":"","url":"https://api.github.com/users/miguelgrinberg","html_url":"https://github.com/miguelgrinberg","followers_url":"https://api.github.com/users/miguelgrinberg/followers","following_url":"https://api.github.com/users/miguelgrinberg/following{/other_user}","gists_url":"https://api.github.com/users/miguelgrinberg/gists{/gist_id}","starred_url":"https://api.github.com/users/miguelgrinberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miguelgrinberg/subscriptions","organizations_url":"https://api.github.com/users/miguelgrinberg/orgs","repos_url":"https://api.github.com/users/miguelgrinberg/repos","events_url":"https://api.github.com/users/miguelgrinberg/events{/privacy}","received_events_url":"https://api.github.com/users/miguelgrinberg/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ansible/ansible-modules-core/labels/bug_report","name":"bug_report","color":"fbca04"},{"url":"https://api.github.com/repos/ansible/ansible-modules-core/labels/P3","name":"P3","color":"fef2c0"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-01-31T07:41:53Z","updated_at":"2015-02-16T06:58:19Z","closed_at":"2015-02-16T06:58:19Z","body":"##### Issue Type:\r\n\r\nBug Report\r\n\r\n##### Ansible Version:\r\n\r\nansible 1.6.10\r\n\r\n##### Environment:\r\n\r\nN/A\r\n\r\n##### Summary:\r\n\r\nThe problem occurs when the `dest` argument given to the `lineinfile` function points to a file that does not have a LF character at the end of the last line. With these conditions, if the function needs to insert a line at the end of the file it will instead append it to the existing last line (i.e. it does not add a LF to the last line in the original file).\r\n\r\n##### Steps To Reproduce:\r\n\r\nCreate a text file that does not have a LF character after the last line. For example:\r\n\r\n    # echo first line >/etc/test.txt\r\n    # echo second line >>/etc/test.txt\r\n    # echo -n third line >>/etc/test.txt\r\n\r\nThen write a task as follows:\r\n\r\n    - name: \r\n      lineinfile:\r\n        dest: /etc/test.txt\r\n        regexp: 'fourth'\r\n        line: \"fourth line\"\r\n\r\n##### Expected Results:\r\n\r\nAfter the above test, the contents of /etc/test.txt should be:\r\n\r\n    first line\r\n    second line\r\n    third line\r\n    fourth line\r\n\r\n##### Actual Results:\r\n\r\nThe contents of /etc/test.txt are:\r\n\r\n    first line\r\n    second line\r\n    third linefourth line\r\n"},"comment":{"url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/comments/74466898","html_url":"https://github.com/ansible/ansible-modules-core/issues/736#issuecomment-74466898","issue_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/736","id":74466898,"user":{"login":"miguelgrinberg","id":2715854,"avatar_url":"https://avatars.githubusercontent.com/u/2715854?v=3","gravatar_id":"","url":"https://api.github.com/users/miguelgrinberg","html_url":"https://github.com/miguelgrinberg","followers_url":"https://api.github.com/users/miguelgrinberg/followers","following_url":"https://api.github.com/users/miguelgrinberg/following{/other_user}","gists_url":"https://api.github.com/users/miguelgrinberg/gists{/gist_id}","starred_url":"https://api.github.com/users/miguelgrinberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miguelgrinberg/subscriptions","organizations_url":"https://api.github.com/users/miguelgrinberg/orgs","repos_url":"https://api.github.com/users/miguelgrinberg/repos","events_url":"https://api.github.com/users/miguelgrinberg/events{/privacy}","received_events_url":"https://api.github.com/users/miguelgrinberg/received_events","type":"User","site_admin":false},"created_at":"2015-02-16T06:58:19Z","updated_at":"2015-02-16T06:58:19Z","body":"Sorry, right, somehow I missed it, but yes, this is fixed in the development version. Closing."}}