有个增加机器后自动注册到 ansible hosts 的需求,闲来无事拿 bash 写了个 webserver 搞了下。在大佬指引下,还加了授权校验。。
just for fun...
bash 还是挺好玩的
What is this
a simple bash script shows the power of nc(netcat)
What does this do
It does something like ansible Dynamic Inventory.
It receive http request from client, and save the reported node IP(encrypted with openssl)
to /etc/ansible/hosts or somewhere else.
How does it work
This script do nothing but combine the awesome linux command togher:
- nc(netcat)
- grep
- sed
- dos2unix
- openssl
- curl
Why Do I do this
The main point of doing this is to show the power of linux command.
You can use it as I ansible dynamic inventory if you know what you are doing, but
it's not recommended to use this in production.
Install
git clone https://github.com/FingerLiu/auth-enabled-bash-server
# centos
yum install -y dos2unix
# ubuntu
apt install -y dos2unix
Usage
start the server
cd auth-enabled-bash-server
./server.sh
start the server in backgroup
nohup ./server.sh & echo $! > run.pid;tail -f nohup.out
stop server
kill `cat run.pid`
start the client
PASSWORD=12345678Afz NODE_IP=192.168.1.111 ./client.sh
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。