Skip to content

Commit

Permalink
chore: refactor functions
Browse files Browse the repository at this point in the history
  • Loading branch information
chornberger-c2c committed Mar 7, 2024
1 parent a5bb306 commit 6eca7ec
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions vagrant_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,9 @@ 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
"""

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 +49,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 +108,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 6eca7ec

Please sign in to comment.