Limit vagrant fields if more than 4
authorlouxnix <sleepycat@gmx.de>
Wed, 10 Feb 2016 07:37:57 +0000 (08:37 +0100)
committerlouxnix <sleepycat@gmx.de>
Wed, 10 Feb 2016 07:37:57 +0000 (08:37 +0100)
Vagrant metadata contains 5 fields:
1455035554,vagrant1,metadata,provider,virtualbox

vagrant --version
Vagrant 1.8.1

ch03/inventory/vagrant.py

index 5a2b69a..767a6f0 100755 (executable)
@@ -21,7 +21,7 @@ def list_running_hosts():
     status = subprocess.check_output(cmd.split()).rstrip()
     hosts = []
     for line in status.split('\n'):
-        (_, host, key, value) = line.split(',')
+        (_, host, key, value) = line.split(',')[:4]
         if key == 'state' and value == 'running':
             hosts.append(host)
     return hosts