예제 #1
0
def main():
    print "Hello there"
    parser = argparse.ArgumentParser()
    parser.add_argument('project_dir', default=None, nargs='?')
    args = parser.parse_args()
    print "PROJECT_DIR", args.project_dir
    config = read_config(args.project_dir)
    install_path, install_playbooks = setup_project(args.project_dir, config)
    print "install_path, install_playbooks", install_path, install_playbooks
    playbooks_path = install_playbooks or install_path
    print "playbooks_path", playbooks_path
    project_root = find_demosthenes_project(path=args.project_dir,
                                            required=False)
    print "project_root", project_root
    config = read_config(project_root)

    if install_path is None:
        playbooks_path = find_playbook_path(config,
                                            project_root,
                                            required=False)
        if playbooks_path:
            install_path = os.path.dirname(playbooks_path)
        else:
            install_path = config['paths']['install-path']
    setup_playbooks(config, install_path, playbooks_path, install_playbooks)
    roles_path = pjoin(install_path, 'roles')
    setup_roles(roles_path, pjoin(install_path, 'galaxy/requirements.yml'))

    return 0
예제 #2
0
def main():
    print "Hello there"
    parser = argparse.ArgumentParser()
    parser.add_argument('project_dir', default=None, nargs='?')
    args = parser.parse_args()
    print "PROJECT_DIR", args.project_dir
    config = read_config(args.project_dir)
    install_path, install_playbooks = setup_project(args.project_dir, config)
    print "install_path, install_playbooks", install_path, install_playbooks
    playbooks_path = install_playbooks or install_path
    print "playbooks_path", playbooks_path
    project_root = find_demosthenes_project(path=args.project_dir,
                                            required=False)
    print "project_root", project_root
    config = read_config(project_root)
    
                                                 
    if install_path is None:
        playbooks_path = find_playbook_path(config,
                                            project_root, required=False)
        if playbooks_path:
            install_path = os.path.dirname(playbooks_path)
        else:
            install_path = config['paths']['install-path']
    setup_playbooks(config, install_path,
                    playbooks_path, install_playbooks)
    roles_path = pjoin(install_path, 'roles')
    setup_roles(roles_path, pjoin(install_path, 'galaxy/requirements.yml'))
        
    return 0
예제 #3
0
def main():
    args = sys.argv[1:]
    #print "hello world", args
    project_root = find_demosthenes_project(required=True)
    #print "project_root", project_root
    config = read_config(project_root)
    #print "Config", config
    playbooks_path = find_playbook_path(config, project_root, required=True)
    #print "Playbooks_Path", playbooks_path

    # FIXME make sure ansible-playbook exists?

    inventory_path = find_inventory_path(project_root)
    print "INVENTORY_PATH", inventory_path
    os.environ['ANSIBLE_HOSTS'] = inventory_path

    ansible_config_file = pjoin(project_root, ANSIBLE_CONFIG_FILE)
    os.environ['ANSIBLE_CONFIG'] = os.path.abspath(ansible_config_file)

    # actually create the ansible_config_file
    generate_ansible_config(ansible_config_file, config,
                            project_root, playbooks_path, inventory_path)
    
    
    # make local find_playbook function
    def find_playbook(playbook):
        path_choices = [
            (project_root, 'playbooks', playbook),
            (project_root, 'ansible', 'playbooks', playbook),
            (playbooks_path, playbook),]
        for fragments in path_choices:
            filename = pjoin(*fragments)
            if os.path.isfile(filename):
                return filename
            
    
    # see if a playbook was specified as the
    # first argument.
    play = None
    if len(args) > 0:
        maybe_play = args[0]
        if os.path.isfile(maybe_play):
            play = maybe_play
        else:
            play = find_playbook('%s.yml' % maybe_play)
        if play is not None:
            args.pop(0)
    if play is None:
        play = find_playbook('site.yml')

    print "Running ansible plabybook from", play, '...'
    
    try:
        retcode = subprocess.call(['ansible-playbook', play] + args)
        sys.exit(retcode)
    except KeyboardInterrupt:
        raise KeyboardInterrupt
예제 #4
0
def main():
    args = sys.argv[1:]
    #print "hello world", args
    project_root = find_demosthenes_project(required=True)
    #print "project_root", project_root
    config = read_config(project_root)
    #print "Config", config
    playbooks_path = find_playbook_path(config, project_root, required=True)
    #print "Playbooks_Path", playbooks_path

    # FIXME make sure ansible-playbook exists?

    inventory_path = find_inventory_path(project_root)
    print "INVENTORY_PATH", inventory_path
    os.environ['ANSIBLE_HOSTS'] = inventory_path

    ansible_config_file = pjoin(project_root, ANSIBLE_CONFIG_FILE)
    os.environ['ANSIBLE_CONFIG'] = os.path.abspath(ansible_config_file)

    # actually create the ansible_config_file
    generate_ansible_config(ansible_config_file, config, project_root,
                            playbooks_path, inventory_path)

    # make local find_playbook function
    def find_playbook(playbook):
        path_choices = [
            (project_root, 'playbooks', playbook),
            (project_root, 'ansible', 'playbooks', playbook),
            (playbooks_path, playbook),
        ]
        for fragments in path_choices:
            filename = pjoin(*fragments)
            if os.path.isfile(filename):
                return filename

    # see if a playbook was specified as the
    # first argument.
    play = None
    if len(args) > 0:
        maybe_play = args[0]
        if os.path.isfile(maybe_play):
            play = maybe_play
        else:
            play = find_playbook('%s.yml' % maybe_play)
        if play is not None:
            args.pop(0)
    if play is None:
        play = find_playbook('site.yml')

    print "Running ansible plabybook from", play, '...'

    try:
        retcode = subprocess.call(['ansible-playbook', play] + args)
        sys.exit(retcode)
    except KeyboardInterrupt:
        raise KeyboardInterrupt