Tag Archives: python

SALT – CLONE YOUR GIT REPO IN A STATE — PYTHON DEV SETUP

GOAL

  • Create a state to be utilised in your working environment
  • Clone git repo!

PERQUISITES:

SaltStack installed on the machine.
https://juhosyrjanen.com/2015/11/05/salty-assignment-i-saltstack/

ENVIRONMENT:

VM1: Running Mint 17.2, Salt master ||  specs

DEV SETUP

I wanted to create a highstate that first installs Git, clones my repository and installs some Python libraries.

GIT

I created this ‘not-so-well-executed’ state to clone my repository for my current project.
State located in /srv/salt/git

git

Running commands in Salt state is not recommended, but this does do the job. My repository is open, therefore there’s no need for passwords in this execution.

I tested this state, it ran fine the first time, but ran into problems using cmd.run.

repo

Instead of using cmd.run, I used cmd.wait, which will only modify directories/scripts if changes are made.

gitfix

Running the state a few times, and all is good.

state

I also added a few line to the git-state to automate the login, so that there’s no need to always enter password on git push.

confgit

 

PYTHON

Another module for the Python installation, done in a similar way to the git-module.
Capture2

Before proceeding, both modules were tested to be working correctly.

Now in the top.sls -file, I added the modules to be set to one of the slaves I have running.
Capture4

Capture3

And then I ran the highstate.
sudo salt slaveVM01 state.highstate

Capture5

It worked.

I created this highstate in order to more easily manage my laptop and other computers I use for development purposes. It will be a lot more easier to run a few states than always manually install python libraries and clone a git repo.

 

  • Copying, modifying and redistributing this and all the other documents in this blog is allowed according to the GNU General Public License (versio 2 or newer).http://www.gnu.org/licenses/gpl.html
  • Based on the Linux course by Tero Karvinen 2015: terokarvinen.com

 

Advertisements

SALT: CHANGE XUBUNTU DEFAULT BACKGROUND WITH SALTSTACK

In Xubuntu and Ubuntu changing the default background is relatively simple. All you need to do is locate the default background file (a binary file) and replace it with the wanted background.

In Xubuntu 14.04, the file is located in
/usr/share/xfce4/backdrops/
And goes by the name of xubuntu-wallpaper.png

In Salt, the easiest way to replace the default background is simply to override it with a state.

First, create a sls. -file for the state. I called mine background/ init.sls. Next you will want to dump your new background into the module folder.

Selection_003

The init.sls -file’s contents are the following:
(I used #!pyobjects to override the file)

#!pyobjects

File.managed("/usr/share/xfce4/backdrops/xubuntu-wallpaper.png", source="salt://background/img.png")

This piece of code will override the default wallpaper. After relogging the background should be updated to your chosen wallpaper.

Running the state:

Selection_004

  • Copying, modifying and redistributing this and all the other documents in this blog is allowed according to the GNU General Public License (versio 2 or newer).http://www.gnu.org/licenses/gpl.html
  • Based on the Linux course by Tero Karvinen 2015: terokarvinen.com

SALTY ASSIGNMENT I: SALTSTACK

ASSIGNMENT:

a) Install SaltStack
b) Create a Package-File-Service state for Salt Stack

Assignment based on the course “Linuxin keskitetty hallinta” by Tero Karvinen

PLATFORM

  • Linux Mint 17.2 running on VirtualBox

GETTING SALTY – INSTALLATION

Firstly after booting the virtual machine, I started by running the basic

sudo apt-get update
sudo apt-get upgrade

To install SaltStack, I followed the instructions on docs.saltstack, found here

SaltStack requires repo.saltstack to be added to the sources.list. I proceeded with the instructions by running these commands:

First I imported the SaltStack repository key

wget -O - https://repo.saltstack.com/apt/ubuntu/ubuntu14/latest/SALTSTACK-GPG-KEY.pub | sudo apt-key add

Capture1

Next I added the repo to sources.list:

sudo nano /etc/apt/sources.list

I Added the following line to the list:

deb http://repo.saltstack.com/apt/ubuntu/ubuntu14/latest trusty main

Next I ran

sudo apt-get update

And then install the SaltStack components wanted! I added the master, minion and ssh components.

sudo apt-get install salt-master salt-minion salt-ssh

And there, installation completed!

Before proceeding I checked the installation status by running

 
$ sudo salt-call --version 

Capture2


PACKAGE-FILE-SERVICE

I created a DHCP-service using Salt and PyObjects:

First I created the .sls -file, that is used to run the state.  I created a directory for all the future Salt stuff in which I also created the sls. -file.

 
sudo mkdir -p /srv/salt
sudoedit /srv/salt/dhcp.sls

Documentation for the use of PyObjects in SaltStack states can be found here – docs.saltstack.
I used the article by Tero Karvinen as refenrence.

To use PyObjects in the sls. -file I first defined the shebang as

 #!pyobjects 

After the  So I added a line to the state-file:

 
with Pkg.installed("bind9"): 
        Service.running("bind9", enable=True)

Since dhcp-service will need bind9 to work properly, it will be installed first. I tested the line above and it worked like a charm.

Capture4

Added dhcp install command:

 
with Pkg.installed("bind9"): 
        Service.running("bind9", enable=True)

with Pkg.installed("isc-dhcp-server"):
        Service.running("isc-dhcp-server", enable=True)

After this, I ran the sls. file again with the command:

 
$ sudo salt-call --state-output=mixed --local state.sls dhcp

Capture5

It worked. This is a very basic installation of dhcp-service. Configuration has not been specified and has to be done by hand when using this implementation.

Later I will post a more detailed guide on how to modify the configuration files in Salt inside the state- file.

  • Copying, modifying and redistributing this and all the other documents in this blog is allowed according to the GNU General Public License (versio 2 or newer).http://www.gnu.org/licenses/gpl.html
  • Based on the Linux course by Tero Karvinen 2015: terokarvinen.com