Freigeben über


PowerShell DSC for Linux, Step by Step

We are privileged to have a guest blogger on Building Clouds, Kristopher Bash.  Kris is a Senior Program Manager in the Microsoft Open Source Technology Center.  Last week at TechEd, Jeffrey Snover was a surprise guest in Don Jones’ presentation, where he demonstrated applying a configuration to a Linux box using PowerShell DSC through standards based management technology, WS-Man.

Kris has authored a step by step guide on the subject and we are lucky to have him share his work via BCB!


 

Building and Installing DSC for Linux

We have just announced the initial availability of a CTP for Windows PowerShell Desired State Configuration for Linux! This initial release is delivered as open-source code, and in this post, I will provide a detailed walkthrough for building and installing the DSC LCM on a Linux computer and applying your first configuration.

Prerequisites

Building OMI 1.0.8 requires the following packages:

  • pam-devel
  • openssl-devel

Walkthrough

In this walkthrough, I will build and install OMI and DSC on a CentOS 6 Linux computer.

· Firstly, I will install the required prerequisite packages to build OMI and the DSC components:

root@lab-dev-02 # yum groupinstall 'Development Tools'

root@lab-dev-02 # yum install pam-devel

root@lab-dev-02 # yum install openssl-devel

 

· Then, I can download and extract OMI 1.0.8 from The Open Group (https://collaboration.opengroup.org/omi/documents/30532/omi-1.0.8.tar.gz). I’ll use /root/downloads as my working directory for OMI and DSC:

root@lab-dev-02 # mkdir /root/downloads

root@lab-dev-02 # cd /root/downloads

root@lab-dev-02 # wget https://collaboration.opengroup.org/omi/documents/30532/omi-1.0.8.tar.gz

root@lab-dev-02 # tar -xvf omi-1.0.8.tar.gz

 

· Next, I’ll configure, build, and install OMI 1.0.8. By default, this will install OMI to /opt/omi-1.0.8/

root@lab-dev-02 # cd omi-1.0.8/

root@lab-dev-02 # ./configure

created /root/downloads/omi-1.0.8/output

root@lab-dev-02 # make

root@lab-dev-02 # make install

Successfully installed under under: ///opt/omi-1.0.8

 

· OMI 1.0.8 is now installed on my computer, and I can move on to installing the DSC components (Local Configuration Manager and Resource Providers). I’ll install Python and download the DSC components:

root@lab-dev-02 # yum install python

root@lab-dev-02 # yum install python-devel

root@lab-dev-02 # cd /root/downloads

root@lab-dev-02 # wget https://github.com/MSFTOSSMgmt/WPSDSCLinux/releases/download/v1.0.0-CTP/PSDSCLinux.tar.gz

root@lab-dev-02 # tar -xvf PSDSCLinux.tar.gzroot@lab-dev-02 # mv ./dsc/* ./

root@lab-dev-02 # ls -l

total 7504

-r-xr-xr-x. 1 3482 3482 78 May 12 09:53 configure

drwxrwxr-x. 2 3482 3482 4096 May 12 09:53 Example DSCs

-rw-r--r--. 1 root root 11862 May 15 08:41 index.html

drwxrwxr-x. 5 3482 3482 4096 May 12 09:53 LCM

-r--r--r--. 1 3482 3482 9144 May 12 09:53 license.txt

-r--r--r--. 1 3482 3482 183 May 12 09:53 Makefile

drwxr-xr-x. 46 root root 4096 May 15 08:45 omi-1.0.8

-rw-r--r--. 1 root root 3623018 May 15 08:41 omi-1.0.8.tar.gz

drwxrwxr-x. 9 3482 3482 4096 May 12 09:57 Providers

-rw-r--r--. 1 root root 4003840 May 12 10:58 PSDSCLinux.tar

-r--r--r--. 1 3482 3482 3958 May 12 09:53 README.txtroot@lab-dev-02 # make

root@lab-dev-02 # make reg

 

Now, both OMI and the Desired State Configuration components (Local Configuration Manager and Resource Providers) are installed.

Running OMI and the LCM

· The DSC installation performed in the previous steps registers the Local Configuration Manager as an OMI provider with OMI, so I simply need to run omiserver to enable DSC:

To run omiserver in an active tty (which is useful for debugging DSC):

root@lab-dev-02 # OMI_HOME=/opt/omi-1.0.8 /opt/omi-1.0.8/bin/omiserver

 

To run omiserver as a background process (daemon):

root@lab-dev-02 # OMI_HOME=/opt/omi-1.0.8 /opt/omi-1.0.8/bin/omiserver -d

 

 

· For ongoing management of the Linux system, we clearly want omiserver to run as a service and start on boot of the Linux computer. For that, we’ll need to create an init script. Here is an example init script:

#! /bin/sh

 ### BEGIN INIT INFO

 # Provides: omiserver

 # Required-Start: $local_fs $remote_fs

 # Required-Stop: $local_fs $remote_fs

 # Default-Start: 3 4 5

 # Default-Stop: 0 1 2 6

 # Short-Description: omiserver initscript

 # Description: omiserver

 ### END INIT INFO

 

 # Do NOT "set -e"

 

 

 export OMI_HOME=/opt/omi-1.0.8/

 DESC="omiserver"

 NAME=omiserver

 PIDFILE=/opt/omi-1.0.8/var/run/omiserver.pid

 SCRIPTNAME=/etc/init.d/$NAME

 

 

 # Define LSB log_* functions.

 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.

 . /lib/lsb/init-functions

 

 #

 # Function that starts the daemon/service

 #

 do_start()

 {

         /opt/omi-1.0.8/bin/omiserver -d

 }

 

 #

Comments

  • Anonymous
    January 01, 2003
    @Bartosz - the "pull" mode is not (yet) supported in this initial CTP release of Desired State Configuration for Linux
  • Anonymous
    January 01, 2003
    The Snover RT from TW, something about flying monkeys. I would add when pigs fly. Air Bacon ! Yummy!
    It has happened, well he hinted forever that DSC was going to be for many platforms...
  • Anonymous
    January 01, 2003
    This should be fun to play with!
  • Anonymous
    January 01, 2003
    Nice news!
    Why in root user? Where sudo?
  • Anonymous
    January 01, 2003
    @_organicit: a few errors in these steps have now been corrected, including moving the contents of /dsc/ up a level and a missing "make" step before "make reg." Thanks for pointing these out!
  • Anonymous
    January 01, 2003
    The comment has been removed
  • Anonymous
    January 01, 2003
    @Ravikanth - good catch, the file name for the tar operation has been corrected.
  • Anonymous
    January 01, 2003
    @Arty: you should be able to compile OMI and the DSC "Local Configuration Manager" for Mac. However, the "resource" providers are pretty-specific to Linux and would likely need a good bit of modification to work on a Mac.
  • Anonymous
    January 01, 2003
    @_organicit: Debian/Ubuntu are completely viable with this DSC release. The only difference should be the prerequisite packages. Using apt-get to install the following should allow you to build on Debian/Ubuntu:
    build-essential
    pkg-config
    python
    python-dev
    libpam-dev
    libssl-dev
  • Anonymous
    May 19, 2014
    I see this is RHEL specific for using yum to add supporting bits to make this work. What's the story on the debian side and running this on Ubuntu??
  • Anonymous
    May 19, 2014
    What are the pros and cons of DSC on linux compared to guix or the nix package manager assuming that one never needs to target non-linux platforms?
  • Anonymous
    May 19, 2014
    The comment has been removed
  • Anonymous
    May 19, 2014
    Would this work for Macs?
  • Anonymous
    May 20, 2014
    Following the above instructions exactly on CentOS 6.5. It seems I'm missing a file. I get an error running 'make reg' as root: /root/downloads/omi-1.0.8/output/bin/omireg: cannot read provider library: /root/downloads/omi-1.0.8/output/lib/libdsccore.so

    Anyone else?
  • Anonymous
    May 20, 2014
    Whoops looks like the instructions have been modified to include a 'make' before 'make reg'

    Works now. Thanks!
  • Anonymous
    May 20, 2014
    The command "tar -xvf PSDSCLinux.tar" should be "tar -xvf PSDSCLinux.tar.gz"
  • Anonymous
    May 20, 2014
    Thanks for the quick turn around Kris!!
  • Anonymous
    May 30, 2014
    I'm trying to use the nxFile cmdlet to copy a directory - but I keep getting "Loading the instance document from the pending location did not succeed". Can you include an example of how to copy an entire directory using DSC?
  • Anonymous
    September 18, 2014
    The comment has been removed
  • Anonymous
    October 23, 2014
    Steve, if you've got a decent build environment set up, you should be able to install the necessary packages on a build server and create a custom package for OMI which can be deployed to the other servers you wish to manage.