Tuesday, 10 April 2018

Automation of salt minion installation from salt master



Install Salt Master : 

sudo yum install https://repo.saltstack.com/yum/redhat/salt-repo-latest-2.el7.noarch.rpm

sudo yum clean expire-cache
sudo yum install salt-master
sudo yum install salt-minion
sudo yum install salt-cloud

For Automatic Minion configuration we need to use saltify provider from salt.

Reference :

https://docs.saltstack.com/en/latest/topics/cloud/saltify.html

Lets start with the creation of saltify provider file :

vi /etc/salt/cloud.providers.d/saltify.conf

************
my-saltify-config:
  minion:
    master: ip_of_salt_master
  driver: saltify
************

now let us create a map file, it basically creates a map between salt profile and minion, The profile name 'setup-minion' will have to defined in the profile section.

you can list down all the minions that you need to configure in this file, I am just adding one minion as an example : 

vi /etc/salt/saltify-map 

************
setup_minion:
  - minion-name:
      ssh_host: ip_of_minion
      ssh_username: root
      key_filename: /root/.ssh/id_rsa
************

I am usin key_filename here, because i have ssh keys setup between the master and minion, if you do not have that you can use username and password.

as mentioned above, now let us create the profile : 

vi /etc/salt/cloud.profiles.d/saltify.conf

************
setup_minion:

  provider: my-saltify-config
************

now that we have all the configuration files ready, let us run a below command which will setup a minion for us :

salt-cloud -m /etc/salt/saltify-map -l debug

this will ask you for a confirmation about minion being setup, once you hit proceed you are all set.

I have added debug just in case it fails the output will help you to understand the error.