Bashible: An Ansible-inspired deployment/automation tool written in Bash (DSL)

栏目: IT技术 · 发布时间: 5年前

内容简介:Bashible is a deployment/automation tool written in Bash (DSL). Inspired by Ansible. Simplifies things and prevents usual mistakes.Features:At the moment, bashible has been used on Arch linux. It may not be compatible with other platforms, because it inter

BASHIBLE

Bashible is a deployment/automation tool written in Bash (DSL). Inspired by Ansible. Simplifies things and prevents usual mistakes.

Features:

  • improved readability
  • unhandled failures prevention
  • skipping already done tasks
  • command chaining
  • working directory always as expected
  • variable checking
  • dependencies; calling sub-scripts
  • delayed tasks executed on finish
  • child termination handler; no processes left running
  • modules: template engine, config editing, etc.
  • nice output

At the moment, bashible has been used on Arch linux. It may not be compatible with other platforms, because it internally uses GNU/sed, grep, etc.

Suggestions and bugfixes are welcome! :-)

Example output

Bashible: An Ansible-inspired deployment/automation tool written in Bash (DSL)

Example script.bash

@ represents a block of tasks, - represents a task. Both @ and - are just bash functions with arguments.

#!/usr/local/bin/bashible

# the working directory is automatically set to the script's
# all tasks will stop execution immediately on failure, unless prefixed by "may_fail"

@ Synchronizing files
  - result synced rsync -av /foo /bar

@ Shutting down the machine
  - when synced
  - when test -f /etc/do-shutdown
  - shutdown -h now

@ Sending an e-mail unless synchronization succeeded
  - when not synced
  - mail me@me.com <<< "synchronzation failed"

Rewritten into pure Bash, the example above could look like this,

#!/bin/bash

cd `dirname $0`
set -eux -o pipefail

echo Synchronizing files
if rsync -av /foo /bar; then
  echo Shutting down the machine
  if test -f /etc/do-shutdown; then
    shutdown -h now
  fi
else
  echo Sending an e-mail unless synchronization succeeded
  mail me@me.com <<< "synchronzation failed"
fi

See also examples in the example directory.

Install & usage

Install bashible and it's modules (sourceable functions - here just one module, "edit"). Copy everything to the same directory.

wget https://raw.githubusercontent.com/mig1984/bashible/master/bashible
wget https://raw.githubusercontent.com/mig1984/bashible/master/bashible.edit
chmod 755 bashible
chmod 755 bashible.edit
mv bashible /usr/local/bin
mv bashible.edit /usr/local/bin

Run the script

bashible my-script.bash ARG1 ARG2 ...

or put she-bang in the beginning of the script and then run it directly

#!/usr/local/bin/bashible

run it

./my-script.bash ARG1 ARG2 ...

Functions

core functions

file-editing functions - found in bashible.edit module

template engine - found in bashible.template module

template TEMPLATE_PATH RESULT_PATH

timeout - found in bashible.timeout module

in_timeout SECS COMMAND ARGS ...

network-oriented functions - found in bashible.net module

wait_for_tcp MATCH up|down

TODO

Write more docs and examples.

Modularize. The bashible core in the version 1.0 should contain only necessary functions and should not ever change. For instance, the delayed and unless_already COMMAND ARGS ... functions now need two temporary files. These files are created on every bashible startup. These functions should go into optional modules instead.

Create tests. Bashible uses GNU/grep, GNU/sed and other programs which may not work properly on all platforms.

Make bashible multiplatform.

Create more modules and/or integrate existing Bash libraries.


以上所述就是小编给大家介绍的《Bashible: An Ansible-inspired deployment/automation tool written in Bash (DSL)》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

刷屏

刷屏

[美] 凯文•阿洛卡 / 侯奕茜、何语涵 / 中信出版社 / 2018-10-1 / 68.00

1. YouTube流行趋势经理,解密如何打造爆款视频 在视频时代,制造互动,才能创造潮流 用户不再是被动的观众,而是主动的传播者 2. 《刷屏》以行内人视角解读: 病毒视频 粉丝经济 网红产业 平台如何为内容创作者赋能 3. 你是否常常被病毒视频刷屏?你是否觉得很多网红火爆到“无法用常理解释”? 视频时代已经到来,我们每天观看网络......一起来看看 《刷屏》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具