Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor functions #20

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading