Skip to content

shakibamoshiri/ansishell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ansishell

What is Ansishell

Ansishell is a command (i.g. job, task, etc) runner either locally or remotely based on a declarative format (e.g yaml) defined to be run.
We know this approach as: Configuration as a Code or CaaC in which we control the operation through human readable configuration.

Here is an example of declarative format

kind: playbook
name: any name you liked

steps:
  - task: run lsblk
    commands:
      - lsblk
      - df
  - task: show list of files
    commands:
      - ls -l
      - pwd

groups:
  - uat

local:
  - /home/shm/
  - /tmp
 
remote:
  - host-1
  - host-2
  - host-3

So with Ansishell we can run those commands either locally or remotely

# dry run
# SSHing into three hosts
#  - host-1
#  - host-2
#  - host-3
# and run any taks we have for groups: 
#  - uat
./ansishell.sh -dr remote -g uat -f playbook.yml

# run
./ansishell.sh remote -g uat -f playbook.yml

# local
# goes over paths we defined
#  - /home/shm/
#  - /tmp
./ansishell.sh -dr local -g uat -f playbook.yml

Ansishell inspired from:

Prerequisite

For parsing yaml, yq is used, so it should be installed any where you run ansishell.
You can download it directly from release page.

Release Notes

1.1.0

  • Add feature
    • read host variables for docker containers
  • update:
    • output formatting
    • sample for exec and docker
  • Bug fixes:
    • exporting variables for containers
    • update samples for shell in a container

1.0.0

  • Bug fixes:
    • change path directory in .local[] accordingly
    • get and set .environment for each task
    • handle single quote in body of a script
  • Add feature:
    • combining sub-commands
  • Making the .local optional
  • Add --install for app subcommand
  • Rename ansishell.sh to ansishell

0.9.3

  • Add more script_debug for better debugging
  • Add set -C for the runner, to avoid file overwrite
  • Enable --dry-run for docker
  • Exit with non-zero if selected group name could not be found
  • Rename "setting" sub-command to "app"

0.9.0

  • 2b4c115 Add ENV feature to exec runner
  • 12aba97 Use loop inside fn
  • 4f6cd28 Add volume and environment object for docker

Defining type to docker in yaml tries to run commands in a image is specified in each - task

kind: playbook
type: docker
...
...
steps:
    - task: try to xyz
      image: alpine:latest

This feature supports:

  • mounting volumes -- docker-compose style
  • environment

0.8.0

  • f76a8eb Add support for run cmd in docker

0.7.0

  • d68a1e5 Rename cli.sh to ansishell.sh
  • 95a4901 Change exec: color to blue with print_info
  • b210bff Add example for both local and remote commands
  • 9b24401 Update setting subcommand

0.6.0

  • bb9fa7a Update help menu for both local and remote subcommands
  • 60e71a4 Rename serv: to host: for remote subcommand

0.5.0

  • 1c3f690 Reuse __ansishell_task_runner() function in local subcommand
  • cdf5040 Rename __remote() to __ansishell_task_runner()

The first implementation was using a __remote function which was private inside remote() function.
Since both local and remote commands had execution part in common, so this function (__remote) was
renamed to used for both subcommands.

0.4.0

  • ed95ae6 Add --file option for remote command

Prior to this point, the CLI was using last argument for a playbook file.
This was not easy to manage, so a -f | --file option added to get a file name for playbook.

0.3.0

  • f304feb Improve help() formant and output guide for users
  • 3697aca Add dry run option --dry-run
  • dbf369d Fix bug: showing just first commands
  • be2ae86 Rename name to task for each step

0.2.1

  • dbf369d Fix bug: showing just first commands

0.2.0

  • cc7ecc9 Update output style for remote sub-command

0.1.0

  • 884d3f4 Update bash strict mode and add title at the top

0.0.0

  • 0d19fef Initial Commit

License

Copyright 20XX Shakiba Moshiri

About

A local or remote runner in pure Bash

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages