Skip to content

Commit

Permalink
fix: disable tags due to overlaps with hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
jomrr committed Mar 15, 2024
1 parent 9a5803a commit 7ada8e0
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions plugins/inventory/ansible_role_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"""

import os

import yaml
from ansible.errors import AnsibleError
from ansible.plugins.inventory import BaseInventoryPlugin


DOCUMENTATION = '''
name: ansible_role_inventory
plugin_type: inventory
Expand Down Expand Up @@ -84,19 +84,19 @@ def parse(self, inventory, loader, path, cache=True):
if search_prefix == '' or dir_name.startswith(search_prefix):
# Extract the part of the directory name following the search prefix
host_name = dir_name[len(search_prefix):]
meta_path = os.path.join(root, dir_name, "meta", "main.yml")
if os.path.exists(meta_path):
with open(meta_path, 'r', encoding='utf-8') as meta_file:
try:
meta_content = yaml.safe_load(meta_file) or {}
galaxy_tags = meta_content.get(
'galaxy_info', {}).get('galaxy_tags', [])
if galaxy_tags:
for tag in galaxy_tags:
self.inventory.add_group(tag)
self.inventory.add_host(host_name, group=tag)
except yaml.YAMLError as exc:
raise AnsibleError(f"Error reading {meta_path}: {exc}") from exc
# meta_path = os.path.join(root, dir_name, "meta", "main.yml")
# if os.path.exists(meta_path):
# with open(meta_path, 'r', encoding='utf-8') as meta_file:
# try:
# meta_content = yaml.safe_load(meta_file) or {}
# galaxy_tags = meta_content.get(
# 'galaxy_info', {}).get('galaxy_tags', [])
# if galaxy_tags:
# for tag in galaxy_tags:
# self.inventory.add_group(tag)
# self.inventory.add_host(host_name, group=tag)
# except yaml.YAMLError as exc:
# raise AnsibleError(f"Error reading {meta_path}: {exc}") from exc
self.inventory.add_host(host_name)
self.inventory.set_variable(host_name,
'ansible_connection', 'local')
Expand Down

0 comments on commit 7ada8e0

Please sign in to comment.