Tuesday, 14 August 2018

Deploy salt-minion using salt-ssh

Typical saltstack stack setup requires installing salt-master and installing salt-minions into all the managed nodes. This task can be tedious when the number as the managed nodes increased.

As long as the managed nodes are accessible via ssh from the master nodes, we can automate this task and deploy salt-minion using salt-ssh.

In your salt-master run the following:
# cd /srv/salt
# mkdir -p deploysalt/conf
# cd deploysalt

Create a file called init.sls with the following content:
Add_Repository:                                                                                                                                       
  pkgrepo.managed
   - name: dt 
   - humanname: DT Repo
   - baseurl: http://download.opensuse.org/repositories/home:/davidtio:/saltstack/openSUSE_Leap_15.0     
   - gpgcheck: 1           
   - gpgautoimport: true 


Install_Minion:                                                                                                                                         
 pkg.installed:                                                                                                                                         
   - pkgs:                                                                                                                                                 
     - salt-minion                                                                                                                                       
     - python3-PyYAML                                                                                                                         
     - python3-tornado                                                                                                                             
     - python3-Jinja2                                                                                                                               
     - python3-msgpack                                                                                                                           
     - python3-pycrypto
     - python3-pyzmq
     - python3-Cython

Update_Master:
 file.managed:
   - name: /etc/salt/minion
   - source: salt://deploysalt/conf/minion

Run_Minion:
 service.running:
   - name: salt-minion
   - enable: true



As you can see the packages to be installed is rather long, this is because I didn't include those packages dependencies in my salt build.  I will be updating salt packages soon !!! 

You will need to put salt minion configuration file into /srv/salt/deploysalt/conf and keep the filename as minion

Assuming your target minion is at 192.168.100.82 with ssh username and password vagrant and vagrant user is sudo account. 

Run the following command from salt-master:
# salt-ssh --roster=scan '192.168.100.82' --user=vagrant --passwd=vagrant --sudo -i \ state.apply deploysalt

Wait for a while and it should be sending the key to salt-master. You can list the key and accept the key using the following command:
# salt-key -L
# salt-key -A
# salt \* test.version

Happy Salting!!! 

No comments:

Post a Comment