GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - sbitio/ansible-sbhell: Ansible role providing modules to ease shell invocations

BranchesTags
Open more actions menu

Latest commit

 

History

22 Commits
22 Commits

Folders and files

NameName
Last commit message
Last commit date
action_plugins
action_plugins
 
 
defaults
defaults
 
 
meta
meta
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 

Repository files navigation

Ansible s(b)hell

Table of Contents

  1. Description
  2. Modules
    • sbhell
    • drush
  3. Example playbook
    • Output
  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.

About

Ansible role providing modules to ease shell invocations

Resources

Readme
MIT license
Activity
Custom properties

Stars

0 stars

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.