This script creates an interactive shell to run common commands on servers using ansible.
ansible
ssh
Clone the repository somewhere and add main.py
into your path (ie: ln -s
$(PWD)/make.py ~/.local/bin/ansible_helper
)
- [ ] TODO: rename modules
- [ ] TODO: have a proper setup.py
Copy config_sample.py
to config.py
in your ansible project.
You also need to configure your ansible hosts and their specific SSH options.
If for example some hosts are not available publicly and you need to go through a jumphost to connect to it, configure your `hosts.yml` accordingly.
For example:
all:
hosts:
public:
ansible_host: 192.168.10.10
private:
ansible_ssh_extra_args: -o "ProxyJump=192.168.10.10"
Start the CLI using python make.py
. Commands have a basic autocomplete and
shows suggestions.
Here is a summary of the available commands:
help
: show possible commands- switch environment:
env nameofenv
. NOTE:env
is just a filter for ansible hosts. For example forsrv1:web:prod
you could use any part or all of it to match an environment. - list hosts configured for the current environment:
hosts
- list hosts impacted by an action:
list someactionname
- check potential impact of an action
check someactionname
- run an action
run someactionname
- ssh into a host:
ssh nameofhost
- show logs:
logs someservicename
.someservicename
is defined in the configuration and will remotely call whatever command you want to run (ie:journalctl -f
)
it is possible to narrow down hosts selected when running an action/check, by adding the following to the command:
-o
: this will pass whatever is passed to -o to ansible. For exemple this will print the helplist main -o="--help"
And this will limit the listing to hosts matching
myhost
list main -l myhost
For now only list
check
and run
support those options
…