def make_ansible_command(hosts_file, identifier, extra_vars=None, tags='', skip_tags='', playbook='site.yml.sample', **kw): """ This utility will compose the command needed to run ansible, capture its stdout and stderr to a file ``verbose``: Optional keyword argument, to flag the need for increased verbosity when running ansible """ if kw.get('verbose'): verbose_flag = '-vvvv' else: verbose_flag = '-v' ceph_ansible_path = get_ceph_ansible_path() playbook = os.path.join(ceph_ansible_path, playbook) ansible_path = which('ansible-playbook') if not extra_vars: extra_vars = dict() extra_vars = json.dumps(extra_vars) cmd = [ ansible_path, verbose_flag, '-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
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
def ansible_exists(): """ Perform a simple check to see if ``ansibl-playbook`` executable is present in the system where the service is running. """ ansible_path = which('ansible-playbook') if not ansible_path: raise SystemCheckError('Could not find ansible in system paths')
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]