mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-07-06 08:35:15 +02:00
Solved other minor bugs
This commit is contained in:
parent
7950a3f517
commit
c3575e5647
@ -115,7 +115,7 @@ def generate_playbook_entries(roles_dir, prefix=None):
|
|||||||
role = roles[role_name]
|
role = roles[role_name]
|
||||||
entries.append(
|
entries.append(
|
||||||
f"- name: setup {role['application_id']}\n"
|
f"- name: setup {role['application_id']}\n"
|
||||||
f" when: {role['application_id']} | application_allowed(group_names, allowed_applications)\n"
|
f" when: ('{role['application_id']}' | application_allowed(group_names, allowed_applications))\n"
|
||||||
f" include_role:\n"
|
f" include_role:\n"
|
||||||
f" name: {role['role_name']}\n"
|
f" name: {role['role_name']}\n"
|
||||||
)
|
)
|
||||||
|
@ -21,7 +21,7 @@ def application_allowed(application_id: str, group_names: list, allowed_applicat
|
|||||||
"""
|
"""
|
||||||
# Ensure group_names is iterable
|
# Ensure group_names is iterable
|
||||||
if not isinstance(group_names, (list, tuple)):
|
if not isinstance(group_names, (list, tuple)):
|
||||||
raise AnsibleFilterError(f"Expected group_names to be a list or tuple, got {type(group_names)}")
|
raise AnsibleFilterError(f"Expected group_names to be a list, str or tuple, got {type(group_names)}")
|
||||||
|
|
||||||
# Must be part of the host's groups
|
# Must be part of the host's groups
|
||||||
if application_id not in group_names:
|
if application_id not in group_names:
|
||||||
@ -29,7 +29,7 @@ def application_allowed(application_id: str, group_names: list, allowed_applicat
|
|||||||
|
|
||||||
# If allowed_applications provided, only allow if ID is in that list
|
# If allowed_applications provided, only allow if ID is in that list
|
||||||
if allowed_applications:
|
if allowed_applications:
|
||||||
if not isinstance(allowed_applications, (list, tuple)):
|
if not isinstance(allowed_applications, (list, tuple, str)):
|
||||||
raise AnsibleFilterError(f"allowed_applications must be a list or tuple if provided, got {type(allowed_applications)}")
|
raise AnsibleFilterError(f"allowed_applications must be a list or tuple if provided, got {type(allowed_applications)}")
|
||||||
return application_id in allowed_applications
|
return application_id in allowed_applications
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class TestApplicationAllowed(unittest.TestCase):
|
|||||||
def test_group_names_wrong_type(self):
|
def test_group_names_wrong_type(self):
|
||||||
# invalid group_names type
|
# invalid group_names type
|
||||||
with self.assertRaises(AnsibleFilterError):
|
with self.assertRaises(AnsibleFilterError):
|
||||||
application_allowed('app1', 'not_a_list', None)
|
application_allowed(1232312, 'not_a_list', None)
|
||||||
|
|
||||||
def test_allowed_applications_edge_cases(self):
|
def test_allowed_applications_edge_cases(self):
|
||||||
# whitespace-only entries do not affect result
|
# whitespace-only entries do not affect result
|
||||||
|
Loading…
x
Reference in New Issue
Block a user