Ansible 2.0.0.2中replace模块报path参数不支持的问题求助
Fixing Ansible Replace Module Error & Variable Reference Issues
Hey there! Let's work through your Ansible problem step by step. You've hit two key issues with your playbook, and we'll resolve both to get your version number update working.
What's Going Wrong?
- Unsupported
pathParameter: Ansible 2.0.0.2'sreplacemodule doesn't recognize thepathargument—this was added in later versions (around 2.3+). Older versions usedest(orname) instead. - Incorrect Variable Handling: Your regex and replacement value aren't referencing variables properly, plus the version number's dots are special regex characters that need escaping.
Step-by-Step Fixes
1. Swap path for dest
In Ansible 2.0.x, the replace module uses dest to specify the target file. Update that line in your playbook, and the parameter error will disappear.
2. Fix Variable References & Regex Escaping
- Variables in Ansible need to be wrapped in
{{ }}—soprev_version|stringbecomes{{ prev_version }}. - The
.in version numbers matches any character in regex, which means your current regex might accidentally match other text. Use theregex_escapefilter to automatically escape all special characters in your old version string.
Updated Playbook (test.yml)
- name: Update the provided system to the next version hosts: localhost run_once: true vars: prev_version: "{{ PREVIOUS_VERSION }}" next_version: "{{ NEXT_VERSION }}" tasks: - name: Update the software version replace: dest: /home/hamza/TrainingWorkspace/Ansible/application_config.txt regexp: "{{ prev_version | regex_escape }}" replace: "{{ next_version }}"
Test the Fix
Run your original command again—it should work now:
ansible-playbook --connection=local --inventory 127.0.0.11, test.yml --extra-vars '{"PREVIOUS_VERSION":"2020.2.2", "NEXT_VERSION": "2020.99.99"}'
After execution, check your application_config.txt file—you should see:
version_info: "2020.99.99"
Quick Note
If you can, consider upgrading your Ansible version to a newer stable release (like 2.10+). Newer versions support the path parameter, have more features, and fewer compatibility quirks like this one.
内容的提问来源于stack exchange,提问作者senjoux
相关产品推荐
相关产品推荐

