Wednesday, November 9, 2016

installing salt-stack: salt-master and salt-minion

Installation

salt master

$ curl -L https://bootstrap.saltstack.com -o install_salt.sh
$ sudo sh install_salt.sh -P -M

Salt master can manage itself, so a Salt minion is installed along with the Salt master.
If you do not want to install the minion, also pass the -N option.
$ sudo sh install_salt.sh -P -M -N

salt minion

-       Default minions will use "salt" as the salt master hostname. you can edit this in the minion's /etc/salt/minions "master: x.x.x.x"
-       when minion first startup, it will look for "salt" and try to put its key to master
$ curl -L https://bootstrap.saltstack.com -o install_salt.sh
$ sudo sh install_salt.sh -P

accepting keys

You may manually accept the minion key from salt master or you may preseed minion with a key generated from salt master
The key name should always match the minion ID which later on you can find from the minion's /etc/salt/minion_id

From salt master:
$ salt-key --gen-keys=minion1

2 files will be generated:
copy and rename the .pub file into /etc/salt/pki/minions/ folder with the minion ID
$ cp minion.pub /etc/salt/pki/minions/minion1

copy these 2 files to minion before starting the salt-minion service
$ scp minion1.pem minion1.pub root@minion1:/etc/salt/pki/minion/

Start | Stop

$ systemctl start salt-minion
$ systemctl start salt-master


Friday, October 14, 2016

MAC OSX Terminal hostname auto-complete

The following script uses a function call to autocomplete hostnames dynamically, and fetches hostnames from the ~/.ssh/known_hosts, ~/.ssh/config and system-wide /etc/hosts file.
In MAC OSX, append below into your user's ~/.bash_profile, save and use new login session to take effect
_complete_hosts () {
     COMPREPLY=()
     cur="${COMP_WORDS[COMP_CWORD]}"
     host_list=`{ 
         for c in /etc/ssh_config /etc/ssh/ssh_config ~/.ssh/config
         do [ -r $c ] && sed -n -e 's/^Host[[:space:]]//p' -e 's/^[[:space:]]*HostName[[:space:]]//p' $c
         done
         for k in /etc/ssh_known_hosts /etc/ssh/ssh_known_hosts ~/.ssh/known_hosts
         do [ -r $k ] && egrep -v '^[#\[]' $k|cut -f 1 -d ' '|sed -e 's/[,:].*//g'
         done
         sed -n -e 's/^[0-9][0-9\.]*//p' /etc/hosts; }|tr ' ' '\n'|grep -v '*'`
     COMPREPLY=( $(compgen -W "${host_list}" -- $cur))
     return 0
 }
 complete -F _complete_hosts ssh
 complete -F _complete_hosts host

Mac OSX cmd auto tab completion

create or edit the ~/.inputrc

set completion-ignore-case on
set show-all-if-ambiguous on
TAB: menu-complete

 open a new terminal session, and use tab to try the auto-completion
There was an error in this gadget