def run_handler(args, config): # TODO: implement -d -a and -v task_name = args['<task>'] task_playbook = config.dig('run', task_name) not_found = [] desired_instances = [] desired_targets = [ x.strip() for x in config.dig('run', task_name)[0]['hosts'].split(',') ] for desired_target in desired_targets: instances = inventory.search(config, [desired_target]) if len(instances) == 0: not_found.append(desired_target) continue instance = inventory.Instance(desired_target, instances[0].address) desired_instances.append(instance) if len(not_found) > 0: logger.error("Unable to find instances: %s" % ", ".join(not_found)) sys.exit(1) if not task_playbook: logger.error("Playbook %s not configured." % repr(task_name)) sys.exit(1) task = RunAnsiblePlaybook(task_name, task_playbook[0], config, desired_instances) task.run()
def test_hostfile_gocase(mocker): config = Config({ 'ansible': { 'become_user': '******', 'become_method': 'sudo' }, 'bastion': { 'address': 'bastion.com', 'options': '-C -o ServerAliveInterval=255' } }) instances = [ Instance(name='devenv-pubsrv', address='13.14.15.16'), Instance(name='testenv-pubsrv', address='1.2.3.4'), Instance(name='testenv-formsvc', address='17.18.19.20') ] task = RunAnsiblePlaybook('name', 'playbook', config, instances) contents = task._build_host_file_contents() assert contents.strip() == """\ devenv-pubsrv ansible_host=13.14.15.16 ansible_ssh_common_args="-o ProxyCommand='ssh -C -o ServerAliveInterval=255 -W %h:%p bastion.com' " testenv-pubsrv ansible_host=1.2.3.4 ansible_ssh_common_args="-o ProxyCommand='ssh -C -o ServerAliveInterval=255 -W %h:%p bastion.com' " testenv-formsvc ansible_host=17.18.19.20 ansible_ssh_common_args="-o ProxyCommand='ssh -C -o ServerAliveInterval=255 -W %h:%p bastion.com' "\ """.strip()