Use jinja2.pass_context instead of contextfilter
Jinja2 3.0.0 deprecated contextfilter in favour of pass_context. 3.1.0 dropped contextfilter. Fall back to contextfilter for Jinja2 2.x. This change also fixes some issues caused by Ansible lint 6.0. Issues found by the yaml plugin are fixed, while the FQCN for builtin actions plugin is skipped. Change-Id: I97b25551eb26da2c9100120bcd646c88fdb33ba6
This commit is contained in:
parent
eba6b368f6
commit
e47ff6bd82
@ -5,3 +5,4 @@ warn_list:
|
||||
- no-changed-when
|
||||
- command-instead-of-shell # Use shell only when shell functionality is required
|
||||
- experimental # all rules tagged as experimental
|
||||
- fqcn-builtins # Use FQCN for builtin actions.
|
||||
|
@ -16,7 +16,11 @@ import re
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
from ansible.module_utils._text import to_text
|
||||
from jinja2 import contextfilter
|
||||
# NOTE: jinja2 3.1.0 dropped contextfilter in favour of pass_context.
|
||||
try:
|
||||
from jinja2 import pass_context
|
||||
except ImportError:
|
||||
from jinja2 import contextfilter as pass_context
|
||||
|
||||
|
||||
class FilterModule(object):
|
||||
@ -64,7 +68,7 @@ def _get_hostvar(context, var_name, inventory_hostname=None):
|
||||
return namespace.get(var_name)
|
||||
|
||||
|
||||
@contextfilter
|
||||
@pass_context
|
||||
def set_libvirt_interfaces(context, node):
|
||||
"""Set interfaces for a node's specified physical networks.
|
||||
"""
|
||||
@ -80,7 +84,7 @@ def set_libvirt_interfaces(context, node):
|
||||
return node
|
||||
|
||||
|
||||
@contextfilter
|
||||
@pass_context
|
||||
def set_libvirt_volume_pool(context, node):
|
||||
"""Set the Libvirt volume pool for each volume.
|
||||
"""
|
||||
@ -118,7 +122,7 @@ def _capabilities_to_dict(capabilities):
|
||||
return capabilities_dict
|
||||
|
||||
|
||||
@contextfilter
|
||||
@pass_context
|
||||
def set_libvirt_boot_firmware(context, node):
|
||||
"""Set the boot firmware for a node."""
|
||||
default_boot_mode = _get_hostvar(context, 'default_boot_mode',
|
||||
@ -150,7 +154,7 @@ def set_libvirt_start_params(node):
|
||||
return node
|
||||
|
||||
|
||||
@contextfilter
|
||||
@pass_context
|
||||
def bridge_name(context, physnet, inventory_hostname=None):
|
||||
"""Get the Tenks bridge name from a physical network name.
|
||||
"""
|
||||
@ -160,7 +164,7 @@ def bridge_name(context, physnet, inventory_hostname=None):
|
||||
inventory_hostname=inventory_hostname)))
|
||||
|
||||
|
||||
@contextfilter
|
||||
@pass_context
|
||||
def source_link_name(context, node, physnet, inventory_hostname=None):
|
||||
"""Get the source veth link name for a node/physnet combination.
|
||||
"""
|
||||
@ -170,7 +174,7 @@ def source_link_name(context, node, physnet, inventory_hostname=None):
|
||||
inventory_hostname=inventory_hostname))
|
||||
|
||||
|
||||
@contextfilter
|
||||
@pass_context
|
||||
def peer_link_name(context, node, physnet, inventory_hostname=None):
|
||||
"""Get the peer veth link name for a node/physnet combination.
|
||||
"""
|
||||
@ -180,7 +184,7 @@ def peer_link_name(context, node, physnet, inventory_hostname=None):
|
||||
inventory_hostname=inventory_hostname))
|
||||
|
||||
|
||||
@contextfilter
|
||||
@pass_context
|
||||
def source_to_peer_link_name(context, source, inventory_hostname=None):
|
||||
"""Get the corresponding peer link name for a source link name.
|
||||
"""
|
||||
@ -190,7 +194,7 @@ def source_to_peer_link_name(context, source, inventory_hostname=None):
|
||||
inventory_hostname=inventory_hostname)
|
||||
|
||||
|
||||
@contextfilter
|
||||
@pass_context
|
||||
def source_link_to_physnet_name(context, source, inventory_hostname=None):
|
||||
""" Get the physical network name that a source veth link is connected to.
|
||||
"""
|
||||
@ -265,7 +269,7 @@ def _link_name(context, node, physnet, inventory_hostname=None):
|
||||
inventory_hostname=inventory_hostname)))
|
||||
|
||||
|
||||
@contextfilter
|
||||
@pass_context
|
||||
def physnet_name_to_index(context, physnet, inventory_hostname=None):
|
||||
"""Get the ID of this physical network on the hypervisor.
|
||||
"""
|
||||
@ -277,7 +281,7 @@ def physnet_name_to_index(context, physnet, inventory_hostname=None):
|
||||
return state[inventory_hostname]['physnet_indices'][physnet]
|
||||
|
||||
|
||||
@contextfilter
|
||||
@pass_context
|
||||
def physnet_index_to_name(context, idx, inventory_hostname=None):
|
||||
"""Get the name of this physical network on the hypervisor.
|
||||
"""
|
||||
|
@ -11,14 +11,14 @@
|
||||
|
||||
- name: Ensure the latest versions of pip and setuptools are installed
|
||||
pip:
|
||||
name: "{{ item.name }}"
|
||||
name: "{{ item }}"
|
||||
state: latest # noqa package-latest
|
||||
virtualenv: "{{ ironic_virtualenv_path }}"
|
||||
extra_args: >-
|
||||
-c {{ ironic_python_upper_constraints_url }}
|
||||
with_items:
|
||||
- { name: pip }
|
||||
- { name: setuptools }
|
||||
- pip
|
||||
- setuptools
|
||||
|
||||
# This is useful to get a uniquely generated temporary path.
|
||||
- name: Create temporary file for pip requirements
|
||||
|
@ -62,7 +62,7 @@
|
||||
- name: Ensure Virtual BMC systemd service is started and enabled
|
||||
systemd:
|
||||
name: "{{ service }}"
|
||||
enabled: yes
|
||||
enabled: true
|
||||
state: started
|
||||
daemon_reload: "{{ service_file.changed }}"
|
||||
become: true
|
||||
|
4
releasenotes/notes/jinja-context-54bce72cab955ca0.yaml
Normal file
4
releasenotes/notes/jinja-context-54bce72cab955ca0.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Fixes an issue seen when using Jinja2 3.1.0.
|
Loading…
Reference in New Issue
Block a user