-
Mac zsh doesn ot have wget anymore.
- Install brew with
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- then
brew install wget
- Install brew with
-
Run ansmenu_install.sh by typing the following in a Terminal:
wget -O - https://raw.githubusercontent.com/IoTPlay/menu_ansible/master/ansmenu_install.sh | bash
-
Edit the variables in
ansmenu_install.sh
- specially where your menu system is on GitHub, variablegitRepo2
. You will find this file innano $HOME/iotplay/GitHub/menu_ansible/ansmenu_install.sh
. -
Log-off, and then on - for new alias commands to take effect.
-
Install your ops_menu with the command
$HOME/iotplay/GitHub/menu_ansible/ansmenu_install.sh --menu
. You can also do same command --help.
-
Clone this repo to local
-
Update the variables as per instructions in these files, about your file locations in ans_0.ini, ans_x.ini, and ans.sh.
-
The instructions, replace:
<user>
with the user of the O/S (We use Mac)<Git_xxx>
- a local folder where you want to keep all the Ansible scripts in. I use a folder which I replicate back to Git.
-
Add a line to your .bash_profile in your HOME directory, with
vi ~/.bash_profile
-- or -- for zsh on Macvi ~/.zshenv
and add the following line:
echo alias ans="zsh $HOME/iotplay/GitHub/menu_ansible/ans.zsh" >> ${HOME}/.zshenv
and for bash (working):
echo "alias ans="zsh $HOME/iotplay/GitHub/menu_ansible/ans.zsh" " >> ${HOME}/.bashrc
My .zshrc looks as follows:
export PATH=$PATH:$HOME/Library/Python/3.8/lib/python/site-packages/pip/:$HOME/Library/Python/3.8/bin
alias ans="zsh $HOME/iotplay/GitHub/menu_ansible/ans.zsh"
The following settings needs to point to where the menu code is:
ansible.cfg
- this must be present in the folder ~/ansible, it has a lineinventory =
that needs to point to where the host file is, in my case,.../git_iotp/ansible/inventory/hosts
An sh-based scripting menu system to manage remote resources using Ansible playbooks.
We deploy docker instances to Raspberry Pi's and other platform to host open source solutions. We tend to end-up at using Node-RED, MariaDB, Mosquitto and others a lot. This leaves lots of administrative tasks for the preparation and managemenentof the RPi's. We wrote normal menu systems using bash, running on the Mac, and on the Pi's to do this with. But 7 months in, we realised this will not be sustainable. Doing maintenance on the bash scripts to configure all were cumbersome, and error-prone. Onle one person knew where all the variables etc were, and if you have not worked in it for some weeks, you need to go read all the scripts again.
So, we set off on a journey to find the right tool to do this, Open source was important. We settled on Ansible, check it out on www.ansible.com. Here you write
But the open source version lacks menu structures, etc, essentially one run the playbooks, with all the command line options from the Terminal. This menu system has 2 lines per menu, a human readable line, displayed on the menu, and the ansible, or other sh-script command line to execute the playbook.
We use Apple Macs, and manage Raspberry Pi's, both from my home LAN, and over the Internet with the menu structure.
When we learned Ansible, we made cryptic notes, with links to other sources. Maybe this will be useful to others. Here are the links to the notes:
TODO. not completed. (ansible, host limitor, etc.)
Several setup files are required:
# | File | what it does |
---|---|---|
1 | ans_0.ini | Stores var's on ansible hosts file, var_files, playbooks, etc. |
2 | ans_1.ini | the first menu (if you only require one, next not needed) |
3 | ans_x.ini | The different menu's variables |
4 | ans_menu.ini | The variable of the active menu to run |
5 | ans.sh | The code that runs the menu |
The main menu, from which you choose other menus.
==== MENU SYSTEM: 1) - Host configs and Docker Images ==================
0 : Passphrase for the ssh id_rsa
1 : ...This Menu - Home...
2 : MENU: Change to menu (2) - Host configs and Docker Images
3 : MENU: Change to menu (3) - Docker Images
4 : MENU: Change to menu (4) - Docker Dev on Apple Mac
5 : MENU: Change to menu (5) - Docker Containers for Client X
6 : MENU: Change to menu (6) - Docker Containers for Client Y
7 : MENU: Change to menu (7) - DevOps GENERAL Commands
----------------------------------------------------------------------
..cmdline 1 = <1..x> - for the action.
----------------------------------------------------------------------
One of the menus.
==== MENU SYSTEM: 2) HOST & DOCKER PREPARATION--- ==================
0 : Passphrase for the ssh id_rsa
1 : MENU: Change to menu (1) - Home
2 : Edit the inventory_limit variable, inv_limit:[rh-02]
3 :
6 : Registry: Private Registry details on rh01
7 : Registry: Private Registry START on rh01 (download image budry/registry-arm)
8 :
9 : Registry: Images on rh01
11 : Docker Image: Pull the proxy, and add to rh01 private registry
12 : Docker Image: Pull the MariaDB, and add to rh01
13 : Docker Image: Build NodeRed from Dockerfile for Mac
14 : Docker Image: Build NodeRed from Dockerfile (usr iotp) for Arm
15 : Docker Image: Build Mosquitto from Dockerfile (usr iotp) for Arm
16 :
17 : Docker Images: LIST them...
----------------------------------------------------------------------
..cmdline 1 = <1..x> - for the action.
----------------------------------------------------------------------
After installation, and config, in a Terminal window, for example menus as shown above:
From any menu:
ans
- Writes the current full menu to screenans 1
- brings up the menu of menu's
From menu 1 - menu of menus:ans 2
- opens menu 2
From any menu, (other than menu 1):ans 2
- opens a vi editor, so you can change the host limitor, for all menu's to use.ans 17
- List all Docker images for the host limits.
- version 1: This version.
- No1: Add a menu version number.
- No2: ans_menu.ini writes a funny file as it switches from menu to menu.
- No3: More instructions of Ansible variables, hosts, playbooks.
-
Clone the "menu system" from https://github.com/IoTPlay/menu_ansible and follow the instructions in the README file.
-
And edit ansible.cfg, in the menu system root to point to
hosts
- Setup SSH key pair, instructions: https://www.freecodecamp.org/news/the-ultimate-guide-to-ssh-setting-up-ssh-keys/
-- and --
- Setting up Passwordless SSH login: https://linuxize.com/post/how-to-setup-passwordless-ssh-login/
# | Command / file | Step |
---|---|---|
00 | ssh-keygen | Generate your pub/priv key pair (normally in ~/.ssh/ file names id_rsa.pub and id_rsa |
01 | ~/.ssh/authorized_keys | On External host - we will Generate a public authentication key and append it to the remote hosts |
02 | ls -al ~/.ssh/id_*.pub | existing SSH keys present?, If not, next step. |
03 | Copy Keys to hosts | ssh-keygen -t rsa -b 4096 -C "email addr" |
04 | ssh-copy-id remote_uname@ip_addr - copy your public key to your server, for instance: | |
04a | rh01 | ssh-copy-id -p2279 [email protected] |
04b | homedig2 | ssh-copy-id -p2279 [email protected] |
05 | vi /etc/ssh/sshd_config | Changes to config files on remote host: |
a. | PasswordAuthentication no | |
b. | ChallengeResponseAuthentication no | |
c. | UsePAM no | |
06 | sudo systemctl restart ssh | Debian - restart ssh |
Or, if ssh-copy-id
not available:
cat ~/.ssh/id_rsa.pub | ssh remote_username@server_ip_address "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
echo alias ans="zsh