Fabric API

Fabric is made up of Core API + Contrib API.

Operations is part of the core api:

  • local – Run a command on the local system.
  • run – Run a shell command on a remote host.
  • sudo – Run a shell command on a remote host, with superuser privileges.
  • put – Upload one or more files to a remote host.
  • get – Download one or more files from a remote host.
  • prompt – Prompt user with text and return the input
  • reboot – Reboot the remote system.

Basic Usage:

fab [-f fabfile.py] [-H hostname] [-p password123] deploy_task:parameter1=xxx,...

Reference:

Advertisements
Posted in Fabric, Python

Fabric (SSH & passwords)

Option 1 – provide password with -p flag

fab -H hostname -p password123 ...
  • Downside: password will show up in process listing
  • Downside: password will show up in command history

Option 2 – get prompted for password

fab -I
Initial value for env.password: *****
  • prevents password from showing up in command history

Options 3 – use ssh key with -i flag

fab -H hostname -i ~/.ssh/keyfile ...
  • Note: this succeeds in connecting, but sudo() will still prompt for password

Option 4 – password inside file

fabric.api import env
env.password = 'yourpassword'

Option 5 – use ssh key inside fabfile.

env.key_filename = '/path/to/keyfile.pem'

Option 6 – piggy back off ssh config.

env.use_ssh_config = True

Option 7 – mess with /etc/sudoers

  • add username for fabric
  • remove need to provide password for specific commands

.

Posted in Fabric, Linux, Python, Security

Users & Groups

Create User (usermod):

  • Note: useradd cannot be used to modify an existing user
useradd <username>
 -c comment, any text, usually user's name
 -d home-directory
 -g primary group; must exist, if not specified a default group is created
 -G group-list (secondary; must exist), definitive not additive (-a)
 -m create home dir
 -M do not create home dir
 -s login shell

passwd <username>

useradd:

  • low level binary compiled into system

adduser:

  • perl script which uses the useradd binary
  • adduser & addgroup are friendlier front end to the low level tools like useradd, groupadd and usermod programs
  • By default gives each user a corresponding group name with same name
  • creates home directory, can be overwritten with –home option, overwrite shell with –shell
  • copies skeleton files into home directory
  • prompts for password
adduser --home ... --shell ... --add_extra_groups username

Modify User (usermod):

usermod [options] <username>
-g primary group
-a append to supplementary groups, use with -G
-G list of groups, comma-separated, must exist
-s login shell (also see chsh)
-d / -m move home director

usermod -a -G secondarygroup username

gpasswd:

gpasswd groupname -a john

Check Groups:

groups username

Create Group:

groupadd - create new group

Files:

  • /etc/passwd – user login information primary group
    • username
    • password(x)
    • uid
    • guid
    • comment-field
    • home-dir
    • login-shell
  • /etc/group – supplementary groups
    • group_name
    • password (blank) :
    • guid :
    • group-list (users who are members)
  • /etc/shadow – stores encrypted passwords + password expiration details

Reference:

Posted in Linux

Jenkins

Settings:

  • JENKINS_HOME – set to ~/.jenkins by default
  • Jenkins Workspace – set to /var/lib/jenkins/workspace

Distributed Builds:

  • master – Jenkins installation that serves HTTP requests, build projects, and distributes load to slaves
  • slaves – nodes that build projects for the master, slaves run the ‘slave-agent’ process they don’t require a full Jenkins installation. Slaves can be added as a project grows.
  • Several methods of communication between master & slaves are possible, but ssh is the most straight forward
  • Projects can be configured to roam freely between projects or stick to a certain slave node
  • https://wiki.jenkins-ci.org/display/JENKINS/Distributed+builds

Reference:

Tagged with:
Posted in Java

Zip commands

zip files

zip <archive.zip> <files-to-compress>
---
unzip archive.zip
unzip archive.zip <file.jpg>
-t test file
-l list files from archive
-j do not make directories

tar files

tar xvf  archive.tar

Z (compressed) files

tar -xZf archive.tar.gz
tar -C /tmp/test archive.tar.gz #extra to /tmp/test (dir must exist)
uncompress archive.tar.gz

Note: z cannot be the last argument, it must come before the f option.

tar.gz files

tar -xzf archive.tar.gz

gzip / .gz files

gunzip archive.gz

bzip2 files

tar xjvf archive.tar.bz2

cheat sheet: http://www.cyberciti.biz/howto/question/general/compress-file-unix-linux-cheat-sheet.php

Tagged with:
Posted in Linux

Installing Fabric

Linux

Installing fabric on LInux/Unix machine is quite simple:

apt-get install fabric 

or

aptitude install fabric

Windows

On windows the process is a bit more complex, see: https://fabric.readthedocs.org/en/1.8/installation.html

The installation page mentions the dependencies that are required, however there are a few gotchas.

1) The PyCrypto library requires a c compiler to build from sources (or a prebuilt binary), otherwise it yields this cryptic error:

error: Unable to find vcvarsall.bat

2) fabric needs a library called ecdsa

———-

In the end these are the steps that finally worked:

  1. python 2.7 –> http://www.python.org/download/
  2. setuptools (easy_install) using ez_setup.py –> https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
  3. pip –> http://www.pip-installer.org/en/latest/installing.html
  4. PyCrypto binary —> http://www.voidspace.org.uk/python/modules.shtml#pycrypto
  5. pip: pip install ecdsa
  6. fabric : pip install fabric

Verify

We can verify the installation by running:

from fabric.api import local
def hello():
    local('echo "hello"')

Execute it:

fab -f test.py hello

Success!

Tagged with: ,
Posted in Fabric, Python

Python package managers

We have the following options:

  • setuptools (easy_install)
    • installed using pythong script: “python ez_setup.py”
    • can install binary files
    • easy_install <module>
  • pip
    • easy_install pip
    • wrapper around easy_install
    • provides uninstallation of modules
    • leaves failed installations in clean state
    • can’t install binaries
    • pip install <module>

Source:

After installation the package managers can be found under:

Python<version>\scripts

Tagged with:
Posted in Python