コード例 #1
0
def make_ansible_command(hosts_file,
                         identifier,
                         extra_vars=None,
                         tags='',
                         skip_tags=''):
    """
    This utility will compose the command needed to run ansible, capture its
    stdout and stderr to a file
    """
    playbook = get_playbook_path()
    ansible_path = which('ansible-playbook')
    if not extra_vars:
        extra_vars = dict()

    extra_vars = json.dumps(extra_vars)

    cmd = [
        ansible_path,
        '-u',
        'ceph-installer',
        playbook,
        '-i',
        hosts_file,
        "--extra-vars",
        extra_vars,
    ]

    if tags:
        cmd.extend(['--tags', tags])

    if skip_tags:
        cmd.extend(['--skip-tags', skip_tags])

    return cmd
コード例 #2
0
ファイル: process.py プロジェクト: ktdreyer/ceph-installer
def make_ansible_command(hosts_file, identifier, extra_vars=None, tags=""):
    """
    This utility will compose the command needed to run ansible, capture its
    stdout and stderr to a file
    """
    playbook = get_playbook_path()
    ansible_path = which("ansible-playbook")
    if not extra_vars:
        extra_vars = dict()

    extra_vars = json.dumps(extra_vars)

    return [ansible_path, "-i", hosts_file, "--extra-vars", extra_vars, "--tags", tags, playbook]
コード例 #3
0
def call_ansible(component,
                 hosts,
                 identifier,
                 tags="",
                 skip_tags="",
                 extra_vars=None):
    """
    This task builds an ansible-playbook command and runs it.

    ``component``: What component we're going to work with: mon, rgw, osd, calamari
    ``hosts``: A list of hosts to run ansible against, these host must be resolvable
    ``tags``: The tags as a comma-delimeted string that represents all the tags
              this ansible call should follow. For example "package-install, other-tag"
    ``skip_tags``: The tags as a comma-delimeted string that represents all the tags
                   this ansible call should skip. For example "package-install, other-tag"
    ``identifier``: The UUID identifer for the task object so this function can capture process
                    metadata and persist it to the database
    """
    if not extra_vars:
        extra_vars = dict()
    component_title = "%s%s" % (component,
                                '' if component.endswith('s') else 's')
    hosts_file = util.generate_inventory_file(component_title, hosts,
                                              identifier)
    command = process.make_ansible_command(hosts_file,
                                           identifier,
                                           tags=tags,
                                           extra_vars=extra_vars,
                                           skip_tags=skip_tags)
    task = models.Task.query.filter_by(identifier=identifier).first()
    task.command = ' '.join(command)
    task.started = datetime.now()
    # force a commit here so we can reference this command later if it fails
    models.commit()
    working_dir = util.get_playbook_path()
    working_dir = os.path.split(working_dir)[0]
    # ansible depends on relative pathing to figure out how to load
    # plugins, among other things. Setting the current working directory
    # for this subprocess call to the directory where the playbook resides
    # allows ansible to properly find action plugins defined in ceph-ansible.
    kwargs = dict(cwd=working_dir)
    out, err, exit_code = process.run(command, **kwargs)
    task.succeeded = not exit_code
    task.exit_code = exit_code
    task.stdout = out
    task.stderr = err
    task.ended = datetime.now()
    models.commit()
コード例 #4
0
ファイル: tasks.py プロジェクト: jcsp/ceph-installer
def call_ansible(component, hosts, identifier, tags="", skip_tags="", extra_vars=None):
    """
    This task builds an ansible-playbook command and runs it.

    ``component``: What component we're going to work with: mon, rgw, osd, calamari
    ``hosts``: A list of hosts to run ansible against, these host must be resolvable
    ``tags``: The tags as a comma-delimeted string that represents all the tags
              this ansible call should follow. For example "package-install, other-tag"
    ``skip_tags``: The tags as a comma-delimeted string that represents all the tags
                   this ansible call should skip. For example "package-install, other-tag"
    ``identifier``: The UUID identifer for the task object so this function can capture process
                    metadata and persist it to the database
    """
    if not extra_vars:
        extra_vars = dict()
    component_title = "%s%s" % (component, '' if component.endswith('s') else 's')
    hosts_file = util.generate_inventory_file(component_title, hosts, identifier)
    command = process.make_ansible_command(hosts_file, identifier, tags=tags, extra_vars=extra_vars, skip_tags=skip_tags)
    task = models.Task.query.filter_by(identifier=identifier).first()
    task.command = ' '.join(command)
    task.started = datetime.now()
    # force a commit here so we can reference this command later if it fails
    models.commit()
    working_dir = util.get_playbook_path()
    working_dir = os.path.split(working_dir)[0]
    # ansible depends on relative pathing to figure out how to load
    # plugins, among other things. Setting the current working directory
    # for this subprocess call to the directory where the playbook resides
    # allows ansible to properly find action plugins defined in ceph-ansible.
    kwargs = dict(cwd=working_dir)
    out, err, exit_code = process.run(command, **kwargs)
    task.succeeded = not exit_code
    task.exit_code = exit_code
    task.stdout = out
    task.stderr = err
    task.ended = datetime.now()
    models.commit()