Giter Club home page Giter Club logo

ansible-sbhell's Introduction

Ansible s(b)hell

Table of Contents

  1. Description
  2. Modules
  3. Example playbook
  4. License
  5. Author Information

Description

This is an Ansible role that provides two modules (action plugins):

  • sbhell: ease shell invocations by providing extra logging capabilities
  • drush: ease performing Drush invocations. Built on top of sbhell.

Modules

sbhell

Perform shell invocations with extra logging capabilities.

It accepts the same parameters as the shell module, but doesn't support the "free form" because of Ansible restrictions. Instead pass the command to run via the command parameter:

- name: sbhell task
  sbhell: command='ls /'

Additionally the module accepts an extra parameter log to enhance the logging of the shell execution. This parameter is a hash with those defaults:

log:
  enabled: true
  #logfile: <autogenerated>
  preserve: false
  debug: true
  • enabled: whether to log the command output to a file
  • logfile: file to save the command output. It is autogenerated if not provided
  • debug: whether to print the command output via debug module

drush

Drush invocations via sbhell.

It accepts the same parameters as the sbhell module above. In this case command is the drush command to run.

Additional parameters:

  • executable: path to drush executable. Defaults to 'drush'
  • args: arguments to provide for the command execution. Defaults to '-y --nocolor'
  • alias: Drush alias. Defaults to '@none'
  • command: Drush command. Defaults to 'status'
  • memory_limit: PHP memory limit. Not set if empty

Example Playbook

- hosts: localhost
  vars:
    drush_executable   : '/opt/drush/9/drush'
    drush_args         : '-y --no-ansi'
    drush_memory_limit : '3072M'

  roles:
    - { role: ansible-sbhell, drush_args: '-y --no-ansi' }

  tasks:
    - name: test shell
      sbhell:
      args:
        command: 'ls /'
        log:
          enabled: true
          debug: true
          preserve: false

    - name: test drush
      drush:
      args:
        alias: '@d8'
        command: php-eval "return ini_get(\"memory_limit\")"

    - name: test drush without an alias
      drush:
      args:
        executable: '/opt/drush/8/drush'
        command: -l http://d7 php-eval "return ini_get(\"memory_limit\")"
        chdir: /var/www/d7/docroot

Output

$ ansible-playbook test.yml

PLAY [localhost] ***************************************************************

TASK [Gathering Facts] *********************************************************
ok: [localhost]

TASK [test shell] **************************************************************
[localhost] Command output is logged to: /tmp/ansible-sbhell-927fad98-d552-4b51-8364-6d03d2d384d3
ok: [localhost] => {
    "changed": false, 
    "cmd": "set -o pipefail; { ls / 2>&1 1>&3 3>&- | tee -a /tmp/ansible-sbhell-927fad98-d552-4b51-8364-6d03d2d384d3; } 3>&1 1>&2 | tee -a /tmp/ansible-sbhell-927fad98-d552-4b51-8364-6d03d2d384d3; rm /tmp/ansible-sbhell-927fad98-d552-4b51-8364-6d03d2d384d3", 
    "command_result": {
        "changed": true, 
        "cmd": "set -o pipefail; { ls / 2>&1 1>&3 3>&- | tee -a /tmp/ansible-sbhell-927fad98-d552-4b51-8364-6d03d2d384d3; } 3>&1 1>&2 | tee -a /tmp/ansible-sbhell-927fad98-d552-4b51-8364-6d03d2d384d3; rm /tmp/ansible-sbhell-927fad98-d552-4b51-8364-6d03d2d384d3", 
        "delta": "0:00:00.003405", 
        "end": "2019-02-14 19:21:09.685161", 
        "invocation": {
            "module_args": {
                "_raw_params": "set -o pipefail; { ls / 2>&1 1>&3 3>&- | tee -a /tmp/ansible-sbhell-927fad98-d552-4b51-8364-6d03d2d384d3; } 3>&1 1>&2 | tee -a /tmp/ansible-sbhell-927fad98-d552-4b51-8364-6d03d2d384d3; rm /tmp/ansible-sbhell-927fad98-d552-4b51-8364-6d03d2d384d3", 
                "_uses_shell": true, 
                "argv": null, 
                "chdir": null, 
                "creates": null, 
                "executable": "/bin/bash", 
                "removes": null, 
                "stdin": null, 
                "warn": true
            }
        }, 
        "rc": 0, 
        "start": "2019-02-14 19:21:09.681756", 
        "stderr": "", 
        "stderr_lines": [], 
        "stdout": "bin\nboot\ndev\netc\nhome\ninitrd.img\ninitrd.img.old\nlib\nlib64\nlost+found\nmedia\nmnt\nopt\nproc\nroot\nrun\nsbin\nsrv\nsys\ntmp\nusr\nvar\nvmlinuz\nvmlinuz.old", 
        "stdout_lines": [
            "bin", 
            "boot", 
            "dev", 
            "etc", 
            "home", 
            "initrd.img", 
            "initrd.img.old", 
            "lib", 
            "lib64", 
            "lost+found", 
            "media", 
            "mnt", 
            "opt", 
            "proc", 
            "root", 
            "run", 
            "sbin", 
            "srv", 
            "sys", 
            "tmp", 
            "usr", 
            "var", 
            "vmlinuz", 
            "vmlinuz.old"
        ]
    }, 
    "delta": "0:00:00.003405", 
    "end": "2019-02-14 19:21:09.685161", 
    "rc": 0, 
    "start": "2019-02-14 19:21:09.681756", 
    "stderr": "", 
    "stderr_lines": [], 
    "stdout": "bin\nboot\ndev\netc\nhome\ninitrd.img\ninitrd.img.old\nlib\nlib64\nlost+found\nmedia\nmnt\nopt\nproc\nroot\nrun\nsbin\nsrv\nsys\ntmp\nusr\nvar\nvmlinuz\nvmlinuz.old", 
    "stdout_lines": [
        "bin", 
        "boot", 
        "dev", 
        "etc", 
        "home", 
        "initrd.img", 
        "initrd.img.old", 
        "lib", 
        "lib64", 
        "lost+found", 
        "media", 
        "mnt", 
        "opt", 
        "proc", 
        "root", 
        "run", 
        "sbin", 
        "srv", 
        "sys", 
        "tmp", 
        "usr", 
        "var", 
        "vmlinuz", 
        "vmlinuz.old"
    ]
}

TASK [test drush] **************************************************************
[localhost] Command output is logged to: /tmp/ansible-sbhell-0ae267c4-f8ab-4bde-b82a-f5a2be128ca9
ok: [localhost] => {
    "changed": false, 
    "cmd": "set -o pipefail; { /opt/drush/9/drush @d8 -y --no-ansi php-eval \"return ini_get(\\\"memory_limit\\\")\" 2>&1 1>&3 3>&- | tee -a /tmp/ansible-sbhell-0ae267c4-f8ab-4bde-b82a-f5a2be128ca9; } 3>&1 1>&2 | tee -a /tmp/ansible-sbhell-0ae267c4-f8ab-4bde-b82a-f5a2be128ca9", 
    "command_result": {
        "changed": true, 
        "cmd": "set -o pipefail; { /opt/drush/9/drush @d8 -y --no-ansi php-eval \"return ini_get(\\\"memory_limit\\\")\" 2>&1 1>&3 3>&- | tee -a /tmp/ansible-sbhell-0ae267c4-f8ab-4bde-b82a-f5a2be128ca9; } 3>&1 1>&2 | tee -a /tmp/ansible-sbhell-0ae267c4-f8ab-4bde-b82a-f5a2be128ca9", 
        "delta": "0:00:00.148535", 
        "end": "2019-02-14 19:21:09.941557", 
        "invocation": {
            "module_args": {
                "_raw_params": "set -o pipefail; { /opt/drush/9/drush @d8 -y --no-ansi php-eval \"return ini_get(\\\"memory_limit\\\")\" 2>&1 1>&3 3>&- | tee -a /tmp/ansible-sbhell-0ae267c4-f8ab-4bde-b82a-f5a2be128ca9; } 3>&1 1>&2 | tee -a /tmp/ansible-sbhell-0ae267c4-f8ab-4bde-b82a-f5a2be128ca9", 
                "_uses_shell": true, 
                "argv": null, 
                "chdir": null, 
                "creates": null, 
                "executable": "/bin/bash", 
                "removes": null, 
                "stdin": null, 
                "warn": true
            }
        }, 
        "rc": 0, 
        "start": "2019-02-14 19:21:09.793022", 
        "stderr": "", 
        "stderr_lines": [], 
        "stdout": "d8d8d8d8d8-1", 
        "stdout_lines": [
            "d8d8d8d8d8-1"
        ]
    }, 
    "delta": "0:00:00.148535", 
    "end": "2019-02-14 19:21:09.941557", 
    "rc": 0, 
    "start": "2019-02-14 19:21:09.793022", 
    "stderr": "", 
    "stderr_lines": [], 
    "stdout": "d8d8d8d8d8-1", 
    "stdout_lines": [
        "d8d8d8d8d8-1"
    ]
}

TASK [test drush without an alias] *********************************************
[localhost] Command output is logged to: /tmp/ansible-sbhell-f754eb69-9c5c-44fa-8714-4c34e43dae55
ok: [localhost] => {
    "changed": false, 
    "cmd": "set -o pipefail; { /opt/drush/8/drush @none -y --no-ansi -l http://d7 php-eval \"return ini_get(\\\"memory_limit\\\")\" 2>&1 1>&3 3>&- | tee -a /tmp/ansible-sbhell-f754eb69-9c5c-44fa-8714-4c34e43dae55; } 3>&1 1>&2 | tee -a /tmp/ansible-sbhell-f754eb69-9c5c-44fa-8714-4c34e43dae55", 
    "command_result": {
        "changed": true, 
        "cmd": "set -o pipefail; { /opt/drush/8/drush @none -y --no-ansi -l http://d7 php-eval \"return ini_get(\\\"memory_limit\\\")\" 2>&1 1>&3 3>&- | tee -a /tmp/ansible-sbhell-f754eb69-9c5c-44fa-8714-4c34e43dae55; } 3>&1 1>&2 | tee -a /tmp/ansible-sbhell-f754eb69-9c5c-44fa-8714-4c34e43dae55", 
        "delta": "0:00:00.089838", 
        "end": "2019-02-14 19:21:10.141745", 
        "invocation": {
            "module_args": {
                "_raw_params": "set -o pipefail; { /opt/drush/8/drush @none -y --no-ansi -l http://d7 php-eval \"return ini_get(\\\"memory_limit\\\")\" 2>&1 1>&3 3>&- | tee -a /tmp/ansible-sbhell-f754eb69-9c5c-44fa-8714-4c34e43dae55; } 3>&1 1>&2 | tee -a /tmp/ansible-sbhell-f754eb69-9c5c-44fa-8714-4c34e43dae55", 
                "_uses_shell": true, 
                "argv": null, 
                "chdir": "/var/www/d7/docroot", 
                "creates": null, 
                "executable": "/bin/bash", 
                "removes": null, 
                "stdin": null, 
                "warn": true
            }
        }, 
        "rc": 0, 
        "start": "2019-02-14 19:21:10.051907", 
        "stderr": "", 
        "stderr_lines": [], 
        "stdout": "'3072M'", 
        "stdout_lines": [
            "'3072M'"
        ]
    }, 
    "delta": "0:00:00.089838", 
    "end": "2019-02-14 19:21:10.141745", 
    "rc": 0, 
    "start": "2019-02-14 19:21:10.051907", 
    "stderr": "", 
    "stderr_lines": [], 
    "stdout": "'3072M'", 
    "stdout_lines": [
        "'3072M'"
    ]
}

PLAY RECAP *********************************************************************
localhost                  : ok=4    changed=0    unreachable=0    failed=0   

License

MIT

Author Information

SB IT Media, S.L.

ansible-sbhell's People

Contributors

jonhattan avatar

Watchers

 avatar  avatar  avatar

ansible-sbhell's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.