Skip to content

Commit dad3b97

Browse files
authored
Update ansible load filter to work with ansible core 2.17 (#23)
* Update ansible load filter to work with ansible core 2.17 Credit to @bewing * Update StackStorm
1 parent 20ff7c0 commit dad3b97

File tree

4 files changed

+412
-313
lines changed

4 files changed

+412
-313
lines changed

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ARG PYTHON
2-
FROM python:3.8
2+
FROM python:3.10
33

44
WORKDIR /jinja101
55
RUN useradd -m jinja101
@@ -19,7 +19,8 @@ COPY --chown=jinja101:jinja101 pyproject.toml .
1919

2020
# poetry does not support subdirectory yet
2121
RUN pip install "git+https://github.com/StackStorm/st2-rbac-backend.git@master#egg=st2-rbac-backend" \
22-
&& pip install "git+https://github.com/StackStorm/[email protected]#subdirectory=st2common" \
22+
&& pip install orquesta "git+https://github.com/StackStorm/[email protected]" \
23+
&& pip install "git+https://github.com/StackStorm/st2.git@master#subdirectory=st2common" \
2324
&& poetry install --no-dev --no-interaction --no-ansi
2425

2526

load_filter.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,43 @@
1-
import sys
1+
import sysconfig
22
from pathlib import Path
33

4-
54
def load_filter_ansible(env):
65
from ansible.plugins.loader import filter_loader, test_loader
76

87
for path in [
98
str(x.resolve())
109
for x in Path(
11-
f"{sys.base_prefix}/lib/python3.8/site-packages/ansible_collections/"
12-
).glob("**/plugins/filter")
10+
f"{sysconfig.get_path('purelib')}/ansible_collections/").glob(
11+
"**/plugins/filter")
1312
if "tests" not in str(x)
1413
]:
1514
filter_loader.add_directory(path)
15+
1616
for fp in filter_loader.all():
17-
for filter_name, filter in fp.filters().items():
18-
path_parts = fp._original_path.split("/")
19-
if path_parts[-5:-3] == ["site-packages", "ansible"]:
20-
env.filters[f"ansible.builtin.{filter_name}"] = filter
21-
env.filters[filter_name] = filter
22-
else:
23-
site_packages = path_parts.index("site-packages")
24-
if path_parts[site_packages + 2 : -3] == [
25-
"community",
26-
"general",
27-
] or path_parts[site_packages + 2 : -3] == ["ansible", "netcommon"]:
28-
env.filters[filter_name] = filter
29-
filter_name = ".".join(
30-
path_parts[site_packages + 2 : -3] + [filter_name]
31-
)
17+
filter_name = fp._load_name
18+
filter = fp.j2_function
19+
path_parts = fp._original_path.split("/")
20+
site_packages = path_parts.index("site-packages")
21+
22+
if path_parts[site_packages : site_packages + 2] == [
23+
"site-packages",
24+
"ansible",
25+
]:
26+
env.filters[f"ansible.builtin.{filter_name}"] = filter
27+
env.filters[filter_name] = filter
28+
else:
29+
if path_parts[site_packages + 2 : -3] == [
30+
"community",
31+
"general",
32+
] or path_parts[site_packages + 2 : -3] == ["ansible", "netcommon"]:
3233
env.filters[filter_name] = filter
34+
filter_name = ".".join(
35+
path_parts[site_packages + 2 : -3] + [filter_name]
36+
)
37+
env.filters[filter_name] = filter
3338

3439
for fp in test_loader.all():
35-
env.tests.update(fp.tests())
40+
env.tests.update({fp.ansible_name: fp._function})
3641

3742

3843
def load_filter_salt(env):

0 commit comments

Comments
 (0)