Skip to content

Commit

Permalink
Merge pull request #20 from chornberger-c2c/chr_patch_5
Browse files Browse the repository at this point in the history
chore: refactor functions
  • Loading branch information
chornberger-c2c authored Mar 8, 2024
2 parents a5bb306 + ec3dca3 commit 57850c3
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions vagrant_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,7 @@ def main():
global MetaClass
MetaClass = type

global _GROUP
_GROUP = 'vagrant' # a default group

global _ssh_to_ansible
_ssh_to_ansible = [('user', 'ansible_user'),
('hostname', 'ansible_host'),
('identityfile', 'ansible_private_key_file'),
('port', 'ansible_port')]

parse_options()

def parse_options():
"""
Parse command line options
"""

# Parse command line options
parser = argparse.ArgumentParser(description="")
parser.add_argument('--list', default=False, dest="list", action="store_true",
help="Produce a JSON consumable grouping of Vagrant servers for Ansible")
Expand All @@ -62,6 +47,8 @@ def parse_options():
global mapping
mapping = {}

_GROUP = 'vagrant' # a default group

if options.list:
list_running_boxes()
ssh_config = get_ssh_config()
Expand Down Expand Up @@ -119,6 +106,11 @@ def get_a_ssh_config(box_id,box_name):
Gives back a map of all the machine's ssh configurations
"""

_ssh_to_ansible = [('user', 'ansible_user'),
('hostname', 'ansible_host'),
('identityfile', 'ansible_private_key_file'),
('port', 'ansible_port')]

output = to_text(subprocess.check_output(["vagrant", "ssh-config", box_id]))
config = SSHConfig()
config.parse(StringIO(output))
Expand Down

0 comments on commit 57850c3

Please sign in to comment.