Beispiel #1
0
def git_update_playbooks():
    _dir = utils.get_appflow_folder() + "/playbooks"
    _pipe = subprocess.PIPE
    out = subprocess.Popen(
        ['git', '-C', _dir, 'pull'], stdout=_pipe, stderr=_pipe)
    for line in iter(out.stdout.readline, b''):
        print(line.decode('utf-8'))
Beispiel #2
0
def provision(tenant: str, env: str, limit: str, tags: str,
              skip_tags: str, firstrun: bool, local: bool):
    """
    This will perform the ansible playbook.
    We pass tenant and environment and all other options as
    --option xys
    in order to respect ansible's syntax.

    :type  tenant: string
    :param tenant: The name of the tenant.

    :type  env: string
    :param env: The name of the tenant.

    :type  limit: string
    :param limit: Comma separated list of hosts to provision.

    :type  tags: string
    :param tags: Comma separated list of tags to exec (default All).

    :type  skip_tags: string
    :param skip_tags: Comma separated list of tags to skip (default None).

    :type  firstrun: bool
    :param firstrun: if it's first run (default False)

    :rtype:   None
    :return:  the function prints to screen the ansible output of the
                execution.
    """
    inventory = utils.get_tenant_dir(tenant) + env + "/inventory"
    appflow_folder = utils.get_appflow_folder()
    playbook = appflow_folder + '/playbooks/generic.yml'
    password_file = utils.get_vault_file(tenant, env)

    # Let's be sure the arguments are strings.
    # In case of multiple arguments (comma separated), convert them back to str.
    limit = utils.format_string_argument(limit)
    tags = utils.format_string_argument(tags)
    skip_tags = utils.format_string_argument(skip_tags)

    tags_argument = []
    # Format arguments for ansible command now.
    if limit is not None:
        tags_argument.append("--limit " + limit)
    if tags is not None:
        tags_argument.append("--tags " + tags)
    if skip_tags is not None:
        tags_argument.append("--skip-tags " + skip_tags)
    # First run! Let's default to the generic user waiting for users provision
    if firstrun:
        tags_argument.append("-k -u ubuntu")
    if local:
        tags_argument.append("-c local")
    os.system('ansible-playbook -b ' + ' '.join(tags_argument) + ' -i ' +
              inventory + ' ' + playbook +
              ' --vault-password-file ' + password_file)
Beispiel #3
0
 def version(self):
     """
     This will print the appflow version and the current appflow-playbooks
     informations.
     """
     print("Appflow Version:", __version__)
     playbooks_folder = utils.get_appflow_folder() + "/playbooks"
     if os.path.exists(playbooks_folder):
         print("Playbooks Version",
               open(playbooks_folder + "/version").read())
Beispiel #4
0
def git_update_playbooks(branch):
    """
    Git pull the latest version of the playbooks.
    You can specify which branch you want to use

    :type  branch: string
    :param branch: The name of the branch
    """
    _dir = utils.get_appflow_folder() + "/playbooks"
    _pipe = subprocess.PIPE
    out = subprocess.Popen(
        ['git', '-C', _dir, 'checkout', branch], stdout=_pipe, stderr=_pipe)
    for line in iter(out.stdout.readline, b''):
        print(line.decode('utf-8'))
    out = subprocess.Popen(
        ['git', '-C', _dir, 'pull'], stdout=_pipe, stderr=_pipe)
    for line in iter(out.stdout.readline, b''):
        print(line.decode('utf-8'))
Beispiel #5
0
def list_tags(tenant, env):
    """
    List all available tags for tenant/environment

    :type  tenant: string
    :param tenant: The name of the tenant.

    :type  env: string
    :param env: The name of the tenant.

    :rtype:   None
    :return:  the function prints to screen the available tags.
    """
    inventory = utils.get_tenant_dir(tenant) + env + "/inventory"
    appflow_folder = utils.get_appflow_folder()
    playbook = appflow_folder + '/playbooks/generic.yml'
    password_file = utils.get_vault_file(tenant, env)

    os.system('ansible-playbook --list-tags -i ' + inventory +
              ' ' + playbook + ' --vault-password-file ' + password_file)