Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

lineinfile not insertafter 'EOF' if line presents in file #2054

Closed
nghnam opened this issue Sep 12, 2015 · 8 comments
Closed

lineinfile not insertafter 'EOF' if line presents in file #2054

nghnam opened this issue Sep 12, 2015 · 8 comments

Comments

@nghnam
Copy link

nghnam commented Sep 12, 2015

Issue Type: Bug Report

Ansible Version: 1.9.3

Ansible Configuration: default

Environment: Ubuntu 14.04

Summary:

lineinfile won't insert line after EOF if line has presented in file.

Steps To Reproduce:

An example ansible task:

- name: test insertafter EOF
  lineinfile:
    dest: /tmp/test.txt
    line: "{{ item.line }}"
    insertafter: 'EOF'
    state: present
  with_items: 
    - { line: Hello Ansible }

My /tmp/test.txt:

Hello Ansible
=============

Expected Results:

Hello Ansible
=============
Hello Ansible

Actual Results:

TASK: [test insertafter EOF] ************************************************** 
ok: [localhost] => (item={'line': 'Hello Ansible'}) => {"backup": "", "changed": false, "item": {"line": "Hello Ansible"}, "msg": ""}

PLAY RECAP ******************************************************************** 
localhost                  : ok=1    changed=0    unreachable=0    failed=0 

And /tmp/test.txt not changed.

In lineinfile.py,
https://github.com/ansible/ansible-modules-core/blob/devel/files/lineinfile.py#L233

The condition if index[0] != -1: checked regexp matched a line in file, but it did not check regexp is defined or not.
I changed this line into if index[0] != -1 and regexp is not None: and re-executed the playbook. It worked as expected.

@ansibot
Copy link

ansibot commented Aug 1, 2016

@ansible ping, this issue is waiting for your response.
click here for bot help

@ansibot
Copy link

ansibot commented Sep 12, 2016

@ansible, ping. This issue is still waiting on your response.
click here for bot help

@ansibot
Copy link

ansibot commented Oct 6, 2016

@ansible, ping. This issue is still waiting on your response.
click here for bot help

2 similar comments
@ansibot
Copy link

ansibot commented Oct 22, 2016

@ansible, ping. This issue is still waiting on your response.
click here for bot help

@ansibot
Copy link

ansibot commented Nov 6, 2016

@ansible, ping. This issue is still waiting on your response.
click here for bot help

@ansibot
Copy link

ansibot commented Nov 22, 2016

@ansible, ping. This issue is still waiting on your response.
click here for bot help

@ansibot
Copy link

ansibot commented Dec 7, 2016

This repository has been locked. All new issues and pull requests should be filed in https://github.com/ansible/ansible

Please read through the repomerge page in the dev guide. The guide contains links to tools which automatically move your issue or pull request to the ansible/ansible repo.

@ansibot
Copy link

ansibot commented Sep 12, 2017

This issue was migrated to ansible/ansible#30046

@ansibot ansibot closed this as completed Sep 12, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants