Tag: puppet

  • Simple Puppet Module – Iterate Through an Array

    puppet-logo

    OK, this is a very simple and quick one.

    I was looking for a simple example of how to iterate through an array in a Puppet module. I basically needed an example of a “for loop” inside a Puppet module that I could, as someone who is not exactly fluent in Ruby, could modify to fit my needs.

    I settled on the format that you see below.

    The “define” code block is basically the work that we want the Puppet module to do. In this case, it’s create a file in /tmp. Think of this line as pretty much just a placeholder for more complex code.

    The “class” code block is where we setup our array of items for the module to “loop” through.

    #
    #
    # Test Module
    #
    #
    
    define myarray_config {
    notify { "Item ${name}": }
    file {"/tmp/$name":
    ensure => present,
    mode => 0777,
    }
    }
    
    class test-module {
    $array = [ 'item1', 'item2', 'item3' ]
    myarray_config { $array: }
    
    }

     

    Now add the following code to your site.pp to make this module part of your site manifest.

    include test-module
    

  • Puppet: Convert a Variable to Lower Case

    noted-felt-puppets-1

     

    This is going to be a very simple example of how to convert a variable to all lowercase inside a Puppet module.

    If you look, which I am sure that you have already…there seems to be a lot of documentation around how to use the Ruby “downcase” function, but not much of it is easy to read if you are not very familiar with Ruby.

    In this example, I create a very simple Puppet module and show how to use the downcase function.

    class test-module (
    $myname = "TEST",
    ){
    
    $myname_downcase = downcase($myname)
    
    file { "/var/tmp/$myname_downcase":
    ensure => present,
    content => "This is a Test File for $myname_downcase",
    }
    }

    In this example I have a Variable called $myname. I am setting $myname to TEST inside the init.pp.

    Note however you would probably never do this. More than likely you would do one of the following:

    1. Set $myname so that it is an external environmental variable
    2. Set $myname to NULL and override in Foreman.

    The meat in this potato is this line here, where we take the $myname variable and munge it into a new variable called $myname_downcase.

    $myname_downcase = downcase($myname)

     

  • Running CloudForms and Puppet Together

    logotype_rh_cloudforms_rgb_black1

    In this instance we are trying to run Red Hat Cloudforms, also known as Manage IQ, and Puppet together on the same RHEL 6 host.

    Our goal here is to push out some configuration to the Cloudforms appliances via Puppet. However we ran into issues as the version of Ruby/Ruby Gems used by Cloudforms is different than the version used by Puppet and they are stepping on each other a bit.

    Here is the error we see when attempting to run Puppet

     

    # puppet agent -t

    /opt/rh/ruby200/root/usr/share/gems/gems/json-1.8.2/lib/json/ext/parser.so: [BUG] Segmentation fault

    ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]

    Aborted (core dumped)

     

    As a workaround we add this code to /usr/bin/puppet.

    %w(GEM_ROOT GEM_HOME GEM_PATH).map do |x|

    ENV.delete x

    end if $0.match(/\A#{‘/usr/bin’}/)

     

     

    We add this right below

    #!/us/bin/ruby

    By no means is this the best way to work around this issue, however it does work and will get you up and running.

     

  • How to Add Standalone Puppet Agents to Foreman

    foreman_medium
    This example will walk us through the process of adding a standalone Puppet host to Foreman for the purpose of managing the host through Puppet. In this instance we are going to create a standalone-hostgroup for the server.

    Note that the Foreman server must be able listening on ports 8140, and 6163 (according to Puppet documentation). My RHEL7 Foreman host was listening on these ports, but the firewall was blocking any inbound connections. I corrected this with the commands shown below.

    First I needed to determine my default firewalld zone.

    # firewall-cmd –get-default-zone

    Then I ran the commands below to punch a hole in the firewall to allow the required traffic. I also reloaded firewald.

    # firewall-cmd –permanent –zone=public –add-port=8140/tcp
    # firewall-cmd –permanent –zone=public –add-port=61613/tcp

    On the puppet client, install the puppet agent

    # yum -y install puppet

    Now we add an entry for the puppet server in /etc/puppet/puppet.conf in section [agent], where <PUPPETSERVER-FQDN> is the FQDN of your Foreman Server

    server = <PUPPETSERVER-FQDN>

    Now save the file.

    Then on the Puppet client run the following command.

    # puppet agent -t waitforcert 60

    Log into Foreman WebUI.
    Navigate to => “Infrastructure” => “Smart Proxies” => “Certificates”

    In the list located the new puppet client and click on sign to accept the key for the new host. The host that I am adding is osd01.lab.localdomain.

    NOTE: Once you have accepted the key you need to run the puppet client again (puppet agent -t)  on the client. Otherwise the client will not appear in on the “All hosts” page

    foreman1

    Now Lets create a new Host Group to use for this server. Come on, its will be a blast.

    Navigate to => “Configure” => “Host groups“. Select the green “New Host Group” button and then add your host group. Here I have added a host group called “Standalone Hosts”. See below.

    foreman2

    Now we need to add our new client to this new host group. We do so by navigating to => “Hosts” => “All hosts“. Then select “Edit” to the left of the host.

    foreman3

    Click “Submit” an the bottom of the page and you are good to go.

  • Packstack Installer Failure: “Error: Could not start Service[rabbitmq-server]: Execution of ‘/usr/bin/systemctl start rabbitmq-server’ returned 1”

    openstack

    Sitting in my hotel room today, I kept running into this error while trying to install OpenStack on a RHEL 7.1 VM running on my laptop. Digging through logs was not helping me one bit, and neither was trying to run “puppet apply” on the failing puppet manifests to see if I could get more info with which to troubleshoot.

    Below is the specific error that I was running into. Note that my RHEL VM’s IP address is 192.168.122.75. This IP address is pre-pended to the puppet module names. Your output, will obviously, vary. Note that this output is truncated.

    Applying 192.168.122.75_amqp.pp
    Applying 192.168.122.75_mariadb.pp
    192.168.122.75_amqp.pp: [ ERROR ]
    Applying Puppet manifests [ ERROR ]

    ERROR : Error appeared during Puppet run: 192.168.122.75_amqp.pp
    Error: Could not start Service[rabbitmq-server]: Execution of ‘/usr/bin/systemctl start rabbitmq-server’ returned 1: Job for rabbitmq-server.service failed. See ‘systemctl status rabbitmq-server.service’ and ‘journalctl -xn’ for details.
    You will find full trace in log /var/tmp/packstack/20150415-183003-mn6Kfx/manifests/192.168.122.75_amqp.pp.log
    Please check log file /var/tmp/packstack/20150415-183003-mn6Kfx/openstack-setup.log for more information
    Additional information:

    Each and every time, the failure occurred when the installer was trying to install/start and rabbitmq-server via the puppet module amqp.pp. Attempting to start rabbitmq manually yielded the same result.

    In this instance, I was trying to be fancy and I had given my VM the hostname packstack01.local (instead of sticking with localhost).

    [root@packstack01 20150415-183254-Kv8u6k]# hostnamectl
    Static hostname: packstack01.local
    Icon name: computer
    Chassis: n/a
    Machine ID: ca64b7fb0c9d4459a4d313dd17b19d76
    Boot ID: fc3397657ed040fca72f3d229d014b74
    Virtualization: kvm
    Kernel: Linux 3.10.0-229.1.2.el7.x86_64
    Architecture: x86_64

    Fresh out of any good ideas, I noticed that a simple nslookup on my made up hostname actually returned results. Results that I would not have expected to be valid.

    [root@packstack01 20150415-183254-Kv8u6k]# nslookup packstack01.local
    Server: 192.168.1.1
    Address: 192.168.1.1#53

    Name: packstack01.local.local
    Address: 198.105.244.104
    Name: packstack01.local.local
    Address: 198.105.254.104

    Despite never referencing my made up hostname in my answer file (by default, the answer file is generated with IP addresses only)  the Rabbitmq service was attempting to connect to itself via hostname, which obviously failed as this is a valid ip and since I was working in a hotel room without proper dns, my server was trying to connect to a machine on the opposite side of the country.

    A quick bit of tinkering in the /etc/hosts file resolved this issue, and I was able to complete my install.

    Note that there are probably many other reasons why one might run into this error during an OpenStack install via Packstack, however this is the one that I ran into, and thankfully it was easy to fix.

    Note to self – always use localhost when working without a valid DNS entry.