Parcourir la source

Allow for a single host specification.

Aurelien il y a 5 ans
Parent
commit
e5c8a605ac
1 fichiers modifiés avec 13 ajouts et 1 suppressions
  1. 13 1
      byrd/main.py

+ 13 - 1
byrd/main.py

@@ -450,6 +450,14 @@ def extract_host(host_string):
     return host_string and host_string.split('@')[-1] or ''
 
 
+def valid_ip(address):
+    try: 
+        socket.inet_aton(address)
+        return True
+    except:
+        return False
+
+
 def get_hosts_and_tasks(cli, cfg):
     # Make sure we don't have overlap between hosts and tasks
     items = list(cfg.networks) + list(cfg.tasks)
@@ -459,6 +467,7 @@ def get_hosts_and_tasks(cli, cfg):
     # Build task list
     tasks = []
     networks = []
+    fixed_hosts = []
     for name in cli.names:
         if name in cfg.networks:
             host = cfg.networks[name]
@@ -466,6 +475,9 @@ def get_hosts_and_tasks(cli, cfg):
         elif name in cfg.tasks:
             task = cfg.tasks[name]
             tasks.append(task)
+        elif valid_ip(name.split(':')[0]):
+            if ':' not in name or name.split(':')[1].isdigit():
+                fixed_hosts.append(name)
         else:
             msg = 'Name "%s" not understood' % name
             matches = spell(cfg.networks, name) | spell(cfg.tasks, name)
@@ -483,7 +495,7 @@ def get_hosts_and_tasks(cli, cfg):
         task.desc = 'Custom command'
         tasks.append(task)
 
-    hosts = list(chain.from_iterable(n.hosts for n in networks))
+    hosts = list(chain.from_iterable(n.hosts for n in networks)) + fixed_hosts
 
     return dict(hosts=hosts, tasks=tasks)