Skip to content

Commit

Permalink
Allow import_playbook from collections (#2018)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Mar 18, 2022
1 parent 9a59bda commit 30b2997
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/playbooks/playbook-parent.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
---
- name: Importing another playbook
ansible.builtin.import_playbook: playbook-imported.yml

- name: Importing playbook from collection
import_playbook: community.molecule.validate
5 changes: 5 additions & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
collections:
# that collection is used during ansible-lint testing for validating our
# ability to import_playbook from a collection.
- name: community.molecule
7 changes: 7 additions & 0 deletions src/ansiblelint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import inspect
import logging
import os
import re
import warnings
from argparse import Namespace
from collections.abc import ItemsView
Expand Down Expand Up @@ -72,6 +73,7 @@
# string as the password to enable such yaml files to be opened and parsed
# successfully.
DEFAULT_VAULT_PASSWORD = "x"
COLLECTION_PLAY_RE = re.compile(r"^[\w\d_]+\.[\w\d_]+\.[\w\d_]+$")

PLAYBOOK_DIR = os.environ.get("ANSIBLE_PLAYBOOK_DIR", None)

Expand Down Expand Up @@ -288,6 +290,11 @@ def _include_children(
):
v = v["file"]

if "import_playbook" in k and COLLECTION_PLAY_RE.match(v):
# Any import_playbooks from collections should be ignored as ansible
# own syntax check will handle them.
return []

# handle include: filename.yml tags=blah
# pylint: disable=unused-variable
(command, args, kwargs) = tokenize(f"{k}: {v}")
Expand Down

0 comments on commit 30b2997

Please sign in to comment.