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!!! 

Thursday, 9 August 2018

Vagrantfile - FOSSTECH Style - Disable NAT

I have been using vagrant to setup my demo system and I don't really like how vagrant setup my virtual machine so I did few changes to it.

I need my virtual machines to be able to interact with each other so I will need my virtual machines to be bridged. I also like to interact using standard ssh using password instead of using vagrant ssh, so my setup will enable password based ssh and disable vagrant ssh.

My environment router is 192.168.100.254 so you will need to adjust the file a little bit to your environment.

Create a directory to contain your virtual machine:
# mkdir node01
# cd node01

Create a file called Vagrantfile containing the following:

 Vagrant.configure("2") do |config| 
 # Use SUSELeap 15.0
 config.vm.box = "opensuse/openSUSE-15.0-x86_64"

 # Configure Hostname and Public IP Address
 config.vm.hostname = "node01"
 config.vm.network "public_network", bridge:"eth0", ip:"192.168.100.51"

 # Make sure the VM has 2 CPU with 4 GB RAM
 config.vm.provider "virtualbox" do |vb|
       vb.memory="4096"
       vb.cpus="2"
 end

 config.vm.provision "shell", inline: <<-SHELL
       # Add default route
       echo "default 192.168.100.254 - eth1" > /etc/sysconfig/network/routes
       # Disable the default NAT interface - this will disable vagrant ssh too
       sed -i "s/STARTMODE.*/STARTMODE=off/" /etc/sysconfig/network/ifcfg-eth0
       # Update resolv.conf
       echo "search fosstech.biz" > /etc/resolv.conf
       echo "nameserver 8.8.8.8" >> /etc/resolv.conf
       echo "nameserver 8.8.4.4" >> /etc/resolv.conf
       # Allow password sshd
       sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' \ /etc/ssh/sshd_config
       systemctl restart sshd
       systemctl restart network &
 SHELL
end


Start your virtual machines:
# vagrant up 

If you never start openSUSE-15.0-x86_64 image before, it will download the image from vagrant and configure the virtual image based on the Vagrantfile above. 

Once the virtual machine is ready, you can ssh into the VM as vagrant user. 

# ssh vagrant@192.168.100.51

The password of vagrant is vagrant too. 

Enjoy your virtual machine !!!

Monday, 6 August 2018

How to Vagrant in SUSE Leap 15

Whenever I need to quickly setup some demo system on my laptop, vagrant has been my go to tools.

vagrant packages can be found in the following repositories:
http://download.opensuse.org/repositories/Virtualization:/vagrant/openSUSE_Leap_15.0/

By default, vagrant works well with virtualbox which is currently part of default openSUSE Leap 15.0.

Install virtualbox and add your current user to vboxusers. Assuming your username is called testuser, run the following command:

> sudo zypper in virtualbox
> sudo usermod -G vboxusers testuser

Logout and re-login again so that your OS reload user group information. You can verify that your user belongs to vboxusers by running the following command:

> id

Now the system is ready for vagrant. Add the repo above and install vagrant

> sudo zypper in vagrant

I usually make a separate directory to keep my demo environment.

> mkdir vagrant
> cd vagrant

You can easily download and startup another openSUSE Leap 15.0 using the following command:

> vagrant init opensuse/openSUSE-15.0-x86_64
> vagrant up
> vagrant ssh 

You will be login into your newly created VMs. 

I might be doing something wrongly, but when I try to initialized my VM, I notice that it is missing directories. I run the following to fix it:

> cd /usr/lib64/ruby/gems/2.5.0/gems/vagrant-2.1.2 
> ln -sf /usr/share/vagrant/plugins .
> ln -sf /usr/share/vagrant/templates .
> ln -sf /usr/share/vagrant/keys .

Let me know if anyone managed to run it without manually linking the directories. See you again in the next how to !!!