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