i have file with string:



MYAPP mean name of applications
DEV means environment
MYUSERNAME means name of user for connection to db

I need to replace these variables according to variables, that i have in some script. I am using this:

- name: Replace line
  shell: sed -i "/{{ name_of_app }}.db.username.{{ name_of_environment }}/c\\{{ name_of_app }}.db.username.{{ name_of_environment }}={{ name_of_user_to_db }}" /path/to/my/apps/{{ name_of_app }}/config/{{ name_of_app }}.config

It works fine, but i see warnings in output of ansible

 [WARNING]: Consider using the replace, lineinfile or template module rather
than running sed.  If you need to use command because replace, lineinfile or
template is insufficient you can add warn=False to this command task or set
command_warnings=False in ansible.cfg to get rid of this message.

I have tried this

- name: Replace line via replace method
    dest: "/path/to/my/apps/{{ name_of_app }}/config/{{ name_of_app }}.config"
    regexp: "{{ name_of_app }}.db.username.{{ name_of_environment }}"
    replace: "{{ name_of_app }}.db.username.{{ name_of_environment }}={{ name_of_user_to_db }}"

and this

- name: Replace line via lineinfile method
    dest: "/path/to/my/apps/{{ name_of_app }}/config/{{ name_of_app }}.config"
    regexp: "{{ name_of_app }}.db.username.{{ name_of_environment }}"
    line: "{{ name_of_app }}.db.username.{{ name_of_environment }}={{ name_of_user_to_db }}"
    backrefs: yes

each time, i have result with failed:

FAILED! => {"changed": false, "msg": "Unsupported parameters for (replace) module: when Supported parameters include: after, attributes, backup, before, content, delimiter, directory_mode, encoding, follow, force, group, mode, owner, path, regexp, remote_src, replace, selevel, serole, setype, seuser, src, unsafe_writes, validate"}

Can you help me, where i have error in my playbook ?

1 Answer 1


The replace and the lineinfile use the path parameter to mark

The file to modify. lineinfile module is used to

ensure[s] a particular line is in a file, or [to] replace an existing line using a back-referenced regular expression.


the replace module if you want to change multiple, similar lines

I believe the dest parameter is used for modules creating new files like template or copy.

Just replace dest with path and both provided examples should work as expected.

  • I think this is the right answer. The official doco indicates dest is an alias for path in both modules, but I am not surprised it is not working in this case.
    – 0xSheepdog
    Nov 14, 2019 at 1:06
  • Ansible changed this behaviour with version 2.3 (released 2017) This answer might be out of date by now. Nov 14, 2019 at 6:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .