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

Py3 vargrant inv #37803

Merged
merged 2 commits into from
Mar 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/py3-vagrant-inv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- Fix bytes/text handling in vagrant dynamic inventory https://github.com/ansible/ansible/pull/37631
13 changes: 9 additions & 4 deletions contrib/inventory/vagrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@
import subprocess
import re
from paramiko import SSHConfig
from cStringIO import StringIO
from optparse import OptionParser
from collections import defaultdict
try:
import json
except:
except Exception:
import simplejson as json

from ansible.module_utils._text import to_text
from ansible.module_utils.six.moves import StringIO


_group = 'vagrant' # a default group
_ssh_to_ansible = [('user', 'ansible_ssh_user'),
('hostname', 'ansible_ssh_host'),
Expand Down Expand Up @@ -74,7 +77,8 @@ def get_ssh_config():

# list all the running boxes
def list_running_boxes():
output = subprocess.check_output(["vagrant", "status"]).split('\n')

output = to_text(subprocess.check_output(["vagrant", "status"]), errors='surrogate_or_strict').split('\n')

boxes = []

Expand All @@ -90,7 +94,7 @@ def list_running_boxes():
def get_a_ssh_config(box_name):
"""Gives back a map of all the machine's ssh configurations"""

output = subprocess.check_output(["vagrant", "ssh-config", box_name])
output = to_text(subprocess.check_output(["vagrant", "ssh-config", box_name]), errors='surrogate_or_strict')
config = SSHConfig()
config.parse(StringIO(output))
host_config = config.lookup(box_name)
Expand All @@ -104,6 +108,7 @@ def get_a_ssh_config(box_name):

return dict((v, host_config[k]) for k, v in _ssh_to_ansible)


# List out servers that vagrant has running
# ------------------------------
if options.list:
Expand Down