Wednesday, July 30, 2014

Puppet in Windows Azure

Few month ago Microsoft announced the availability of Azure VM images with Puppet agent installed.
Puppet is a piece of software useful to manage hundreds o thousands of machines from a single point of management.
Today, I have tested this feature and here are the notes, I hope they will be useful to you.

  1. Deploy Puppet Azure virtual machine following this guide
    • Be careful with the ENDPOINTS, you have to create at least these: HTTPS port 443 for the PE console, Puppet open port 8140 for puppet agents and MCollective port 61613 for MCollective.
    • Be patient after machine gets started, it take several minutes to deploy Puppet server, it depends on the virtual hardware but it is more or less 15 minutes.
    • User login is located in the file  /etc/puppetlabs/installer/answers.install
    • Password is located in the file /etc/puppetlabs/installer/database_info.install
  2. Deploy Azure VM with Puppet agent installed
    • Test puppet agent --test command in the new deployed machine
    • Register puppet agent approving it from web admin console (In the master server)
  3. Connect via SSH to Master
    • First of all go to manifest directory, which is located at /etc/puppetlabs/puppet/manifests
    • Install the Powershell provider (for Windows VMs) into master with: puppet module install joshcooper-powershell in the Master console
    • Edit site.pp file which is located at /etc/puppetlabs/puppet/manifests <-- This is the main file in Puppet, in this file you are going to define the classes and how you are going to distribute them to nodes/agents
    • Here is an example of site.pp file, pay attention to class test and node testpuppet:
      # This file (/etc/puppetlabs/puppet/manifests/site.pp) is the main entry point
      # used when an agent connects to a master and asks for an updated configuration.
      # Global objects like filebuckets and resource defaults should go in this file,
      # as should the default node definition. (The default node can be omitted
      # if you use the console and don't define any other nodes in site.pp. See
      # for more on
      # node definitions.)

      ## Active Configurations ##

      # This configures puppet agent and puppet inspect to back up file contents when
      # they run. The Puppet Enterprise console needs this to display file contents
      # and differences.

      # Define filebucket 'main':
      filebucket { 'main':
      server => '',
      path => false,

      # Make filebucket 'main' the default backup location for all File resources:
      File { backup => 'main' }

      # Node definitions in this file are merged with node data from the console. See
      # for more on
      # node definitions.

      class test23{
      exec { 'rename-guest':
      command => '$(Get-WMIObject Win32_UserAccount -Filter "Name=\'guest\'").Rename("new-guest")',
      unless => 'if (Get-WmiObject Win32_UserAccount -Filter "Name=\'guest\'") { exit 1 }',
      provider => powershell,

      class test24{
      exec { 'new-file-windows':
      command => 'New-Item c:\new_file.txt -type file',
      provider => powershell,

      class audio_SRV_ON{
      service {'Audiosrv':
      ensure => running,
      enable => true,

      # The default node definition matches any node lacking a more specific node
      # definition. If there are no other nodes in this file, classes declared here
      # will be included in every node's catalog, *in addition* to any classes
      # specified in the console for that node.

      node default {
      # This is where you can declare classes for all nodes.
      # Example:
      # class { 'my_class': }

      node '' {
      # This is where you can declare classes for all nodes.
      # Example:
      class { 'test23': }

      You don´t need to restart the service to reload the configuration file.
      Agents are updated every 30 minutes with the site.pp settings, this time can be changed.
      You can force agent to update running again puppet agent --test in the node.
      You can include files extra files into site.pp with include command
      When you add a class to sites.pp this appears at the web interface, now you can add it by clicking over the add class button.
      If you want to apply class to group of nodes, you have to create a group in the web interface, add nodes to it and later apply a set classes to this group.
Let me know how it went ;).

1 comment: