Пример #1
0
def main():
    if in_tmux():
        print(
            "echo 'Please exit current tmux session in order to use ansibleconnect'"
        )
        exit(1)
    args = parse_arguments()
    inventory = InventoryAdapter(args.inventory)
    hostnames = parse_hostnames(args.hosts)
    groups, no_groups = parse_inventory_groups(args.groups)
    if hostnames:
        hosts_list = inventory.get_hosts_by_names(hostnames)
    else:
        hosts_list = inventory.get_hosts_by_group(groups, no_groups)
    if not hosts_list:
        print("echo 'No hosts matched given criteria'")
        exit(1)
    variables = parse_vars(args.variables)
    no_variables = parse_vars(args.no_variables)
    if variables or no_variables:
        hosts_list = inventory.get_hosts_by_variables(hosts_list, variables,
                                                      no_variables)
    hosts_adapters = [AnsibleHostAdapter(host) for host in hosts_list]
    tmux_script = create_tmux_script(hosts_adapters)
    print(tmux_script)
Пример #2
0
 def test_parse_inventory_groups_multi_group(self, input_argument,
                                             expected_groups,
                                             expected_no_groups):
     groups, no_groups = parse_inventory_groups(input_argument)
     self.assertListEqual(sorted(expected_groups), sorted(groups))
     self.assertListEqual(sorted(expected_no_groups), sorted(no_groups))
Пример #3
0
 def test_parse_inventory_groups_none(self):
     groups, no_groups = parse_inventory_groups(None)
     self.assertEqual([], groups)
     self.assertEqual([], no_groups)
Пример #4
0
 def test_parse_inventory_groups_single_no_group(self):
     groups, no_groups = parse_inventory_groups('!test_group')
     self.assertListEqual(['test_group'], no_groups)
     self.assertEqual([], groups)