模板化字符串时出现模板错误:没有名为 'relpath' 的过滤器
Getting template error while templating string: No filter named 'relpath'
当 运行 playbook (OS - macOS 12.3.1 (21E258))
时低于 msg
TASK [metrics-base : Copy riemann files] *********************************************************************************************************************
fatal: [localhost]: FAILED! => {}
MSG:
template error while templating string: No filter named 'relpath'.. String: {{ metrics_base_location }}/{{ item.path | relpath(role_path ~ '/files/') }}
任务:
- name: Copy riemann files
become: true
copy:
src: "{{ item.path }}"
dest: "{{ metrics_base_location }}/{{ item.path | relpath(role_path ~ '/files/') }}"
mode: preserve
loop: "{{ riemann_files.files }}"
loop_control:
label: "{{ metrics_base_location }}/{{ item.path | relpath(role_path ~ '/files/') }}"
我通过 pip 虚拟环境安装了 ansible
Ansible 版本:
ansible 2.9.14
config file = /Users/priyaranjan.m/Work/grey_orange/butler/gtp-deployer/ansible.cfg
configured module search path = ['/Users/priyaranjan.m/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/priyaranjan.m/Work/grey_orange/butler/gtp-deployer/venv/lib/python3.9/site-packages/ansible
executable location = /Users/priyaranjan.m/Work/grey_orange/butler/gtp-deployer/venv/bin/ansible
python version = 3.9.13 (main, May 24 2022, 21:13:51) [Clang 13.1.6 (clang-1316.0.21.2)]
ansible-playbook 2.9.14
config file = /Users/priyaranjan.m/Work/grey_orange/butler/gtp-deployer/ansible.cfg
configured module search path = ['/Users/priyaranjan.m/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/priyaranjan.m/Work/grey_orange/butler/gtp-deployer/venv/lib/python3.9/site-packages/ansible
executable location = /Users/priyaranjan.m/Work/grey_orange/butler/gtp-deployer/venv/bin/ansible-playbook
python version = 3.9.13 (main, May 24 2022, 21:13:51) [Clang 13.1.6 (clang-1316.0.21.2)]
似乎是 Jinja 版本兼容性问题。
这让我想起了这个github issue
尝试至少升级到 Ansible 2.9.22
当 运行 playbook (OS - macOS 12.3.1 (21E258))
时低于 msgTASK [metrics-base : Copy riemann files] *********************************************************************************************************************
fatal: [localhost]: FAILED! => {}
MSG:
template error while templating string: No filter named 'relpath'.. String: {{ metrics_base_location }}/{{ item.path | relpath(role_path ~ '/files/') }}
任务:
- name: Copy riemann files
become: true
copy:
src: "{{ item.path }}"
dest: "{{ metrics_base_location }}/{{ item.path | relpath(role_path ~ '/files/') }}"
mode: preserve
loop: "{{ riemann_files.files }}"
loop_control:
label: "{{ metrics_base_location }}/{{ item.path | relpath(role_path ~ '/files/') }}"
我通过 pip 虚拟环境安装了 ansible
Ansible 版本:
ansible 2.9.14
config file = /Users/priyaranjan.m/Work/grey_orange/butler/gtp-deployer/ansible.cfg
configured module search path = ['/Users/priyaranjan.m/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/priyaranjan.m/Work/grey_orange/butler/gtp-deployer/venv/lib/python3.9/site-packages/ansible
executable location = /Users/priyaranjan.m/Work/grey_orange/butler/gtp-deployer/venv/bin/ansible
python version = 3.9.13 (main, May 24 2022, 21:13:51) [Clang 13.1.6 (clang-1316.0.21.2)]
ansible-playbook 2.9.14
config file = /Users/priyaranjan.m/Work/grey_orange/butler/gtp-deployer/ansible.cfg
configured module search path = ['/Users/priyaranjan.m/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/priyaranjan.m/Work/grey_orange/butler/gtp-deployer/venv/lib/python3.9/site-packages/ansible
executable location = /Users/priyaranjan.m/Work/grey_orange/butler/gtp-deployer/venv/bin/ansible-playbook
python version = 3.9.13 (main, May 24 2022, 21:13:51) [Clang 13.1.6 (clang-1316.0.21.2)]
似乎是 Jinja 版本兼容性问题。
这让我想起了这个github issue
尝试至少升级到 Ansible 2.9.22