python on puppet

102 views
Skip to first unread message

bapi...@cloudwick.com

unread,
Apr 22, 2016, 2:04:29 PM4/22/16
to Puppet Users
Hi all,

I am trying to manage python packages from puppet.I wanted to run the following commands without using EXEC..

After installing python-setuptools i tried to install pika using pip as provider .. but it did not work.

What is the best way to puppetize this??

Thank You
Bapi


sudo yum install python-setuptools


sudo easy-install pip

sudo easy-install argparse

sudo /usr/bin/pip install pika

Rob Nelson

unread,
Apr 22, 2016, 2:33:55 PM4/22/16
to puppet...@googlegroups.com
Bapi,

Searching the forge (https://forge.puppet.com) is my first stop. A search on python or pip turn up a number of hits. There's an approved puppet module that looks like it might be helpful: https://forge.puppet.com/stankevich/python. Approved modules must meet some standards so are generally more interesting than non-approved modules, but you should always review modules to find which is the best fit for you now and in the future.

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/ed850c4b-628e-4a66-bd83-bb3dbd93d68c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gary Greene

unread,
Apr 22, 2016, 2:59:24 PM4/22/16
to puppet...@googlegroups.com
Since puppet runs as root, generally, you wouldn’t need the sudo for these commands. 

Note, I’m not a python guy, so testing for the install of these may or may not work this way, since if these eggs are apps, they’ll likely not have modules with the same name as the driver script...

Anyway, back to your question, if I were doing this, and couldn’t use the number of existing options on the forge for whatever reason, I’d do something like this:

--- puppet code ---

# should really get this from some other source instead of hard-coding it...
PYTHON_PREFIX = “/usr"

# same for the package name.
package { “python-setuptools”:
ensure   => installed,
provider => yum
}

exec { “pip_install”:
command => “$PYTHON_PREFIX/bin/easy-install pip”,
require => Package[ ‘python-setuptools’,
unless  => “test -x /usr/bin/pip"
}

exec { “argparse_install":
command => “$PYTHON_PREFIX/bin/easy-install argparse”,
require => Exec[ ‘pip_install’ ],
unless  => 'python -c “import argparse” &> /dev/null'
}

exec { “pika_install”:
command => “$PYTHON_PREFIX/bin/pip install pika”,
require => Exec[ ‘pip_install’ ],
unless  => 'python -c “import pika” &> /dev/null'
}

--- end of puppet code ---

Note that these kinds of chains can be fragile if not tested well for your environment.

--
Gary L. Greene, Jr.
==============================================================================
Volunteer developer of the KDE F/OSS project and Project Lead for AltimatOS
    http://www.kde.org/                 http://www.altimatos.com/
==============================================================================

Bapi raj Loya

unread,
Apr 22, 2016, 3:04:05 PM4/22/16
to puppet...@googlegroups.com
Hi Gary 

can i set environment in package for /usr/bin ??

--
You received this message because you are subscribed to a topic in the Google Groups "Puppet Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/puppet-users/55S_4ON7N6g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/F8A2A601-6964-4E23-B237-72ACE1902F55%40tolharadys.net.

Ramin K

unread,
Apr 22, 2016, 3:10:10 PM4/22/16
to puppet...@googlegroups.com
On 4/22/16 11:04 AM, bapi...@cloudwick.com wrote:
> Hi all,
>
> I am trying to manage python packages from puppet.I wanted to run the
> following commands *without using EXEC..*
> *
> *
> *After installing python-setuptools i tried to install pika using pip as
> provider .. but it did not work.*


If the pip provider didn't work, it might be an ordering or dependency
problem. Does a second run succeed? We do something like this for ruby
gems. In your case I think you would need to install the os pip package
as well.

class ruby::devel {

package { 'rubygems': ensure => installed, }
# etc etc

Class['ruby::devel'] -> Package <| provider == gem |>

Ramin

Gary Greene

unread,
Apr 22, 2016, 3:10:14 PM4/22/16
to puppet...@googlegroups.com
On Apr 22, 2016, at 12:03 PM, Bapi raj Loya <bapi...@cloudwick.com> wrote:

Hi Gary 

can i set environment in package for /usr/bin ??


You can set it to whatever you want it to be, as appropriate to your environment. All I was doing was giving an example, modify as desired.

Asya Dvorkin

unread,
Apr 22, 2016, 3:13:49 PM4/22/16
to puppet...@googlegroups.com
Hello, Bapi.

Why not install python-pip package and use pip as a provider?

"pika":
require => Package["python-pip"],
ensure => present,
provider => pip;

Asya

----- Original Message -----
From: "bapi loya" <bapi...@cloudwick.com>
To: "Puppet Users" <puppet...@googlegroups.com>
Sent: Friday, April 22, 2016 2:04:29 PM
Subject: [Puppet Users] python on puppet

Hi all,

I am trying to manage python packages from puppet.I wanted to run the
following commands *without using EXEC..*

*After installing python-setuptools i tried to install pika using pip as
provider .. but it did not work.*

*What is the best way to puppetize this??*

*Thank You*
*Bapi*







*sudo yum install python-setuptoolssudo easy-install pipsudo easy-install
argparsesudo /usr/bin/pip install pika*

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/ed850c4b-628e-4a66-bd83-bb3dbd93d68c%40googlegroups.com.

Gary Greene

unread,
Apr 22, 2016, 3:15:24 PM4/22/16
to puppet...@googlegroups.com


> On Apr 22, 2016, at 12:10 PM, Asya Dvorkin <advo...@CS.Princeton.EDU> wrote:
>
> Hello, Bapi.
>
> Why not install python-pip package and use pip as a provider?
>
> "pika":
> require => Package["python-pip"],
> ensure => present,
> provider => pip;
>
> Asia
>

I’d forgotten about that! Good point. That lowers the use of Execs right there.

--
Gary L. Greene, Jr.
==============================================================================
Volunteer developer of the KDE F/OSS project and Project Lead for AltimatOS
http://www.kde.org/ http://www.altimatos.com/
==============================================================================


> ----- Original Message -----
> From: "bapi loya" <bapi...@cloudwick.com>
> To: "Puppet Users" <puppet...@googlegroups.com>
> Sent: Friday, April 22, 2016 2:04:29 PM
> Subject: [Puppet Users] python on puppet
>
> Hi all,
>
> I am trying to manage python packages from puppet.I wanted to run the
> following commands *without using EXEC..*
>
> *After installing python-setuptools i tried to install pika using pip as
> provider .. but it did not work.*
>
> *What is the best way to puppetize this??*
>
> *Thank You*
> *Bapi*
>
>
>
>
>
>
>
> *sudo yum install python-setuptoolssudo easy-install pipsudo easy-install
> argparsesudo /usr/bin/pip install pika*
>
> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/ed850c4b-628e-4a66-bd83-bb3dbd93d68c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/2113651282.3707077.1461352259773.JavaMail.zimbra%40cs.princeton.edu.

bapi...@cloudwick.com

unread,
Apr 22, 2016, 3:52:20 PM4/22/16
to Puppet Users
Hi Asya:

Im gettting an error when i tried to include that:

Error:

Error: Execution of '/usr/bin/yum -d 0 -e 0 -y install python-pip' returned 1: Error: Nothing to do
Error: /Stage[main]/Ingest/Package[python-pip]/ensure: change from purged to present failed: Execution of '/usr/bin/yum -d 0 -e 0 -y install python-pip' returned 1: Error: Nothing to do
Notice: /Stage[main]/Ingest/Package[pika]: Dependency Package[python-pip] has failures: true
Warning: /Stage[main]/Ingest/Package[pika]: Skipping because of failed dependencies

Thank You
Bapi

Andrew Grimberg

unread,
Apr 22, 2016, 5:25:33 PM4/22/16
to puppet...@googlegroups.com
Bapi,

I would go with Rob's suggestion here as well. I can definitely attest
to stankevich/python being a good module as I use it extensively.

Here's a code snippet that would do what you want using that module:

--[cut]--
class { 'python':
version => 'system',
pip => 'present',
dev => 'present', # needed by a lot of modules, let's be safe
}

python::pip { ['argparse', 'pika']:
ensure => 'present',
}
--[/cut]--

-Andy-

On 04/22/2016 11:33 AM, Rob Nelson wrote:
> Bapi,
>
> Searching the forge (https://forge.puppet.com) is my first stop. A
> search on python or pip turn up a number of hits. There's an approved
> puppet module that looks like it might be helpful:
> https://forge.puppet.com/stankevich/python. Approved modules must meet
> some standards so are generally more interesting than non-approved
> modules, but you should always review modules to find which is the best
> fit for you now and in the future.
>
>
> Rob Nelson
> rnel...@gmail.com <mailto:rnel...@gmail.com>
>
> On Fri, Apr 22, 2016 at 2:04 PM, <bapi...@cloudwick.com
> <mailto:bapi...@cloudwick.com>> wrote:
>
> Hi all,
>
> I am trying to manage python packages from puppet.I wanted to run
> the following commands *without using EXEC..*
> *
> *
> *After installing python-setuptools i tried to install pika using
> pip as provider .. but it did not work.*
> *
> *
> *What is the best way to puppetize this??*
> *
> *
> *Thank You*
> *Bapi*
> *
> *
>
> *
> |
> *
> |
> sudo yum install python-setuptools
> |
> *
>
> sudo easy-install pip
>
> sudo easy-install argparse
> *
> |
>
> sudo /usr/bin/pip install pika
> |
> *
> |
> *
>
> --
> You received this message because you are subscribed to the Google
> Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to puppet-users...@googlegroups.com
> <mailto:puppet-users...@googlegroups.com>.
> <https://groups.google.com/d/msgid/puppet-users/ed850c4b-628e-4a66-bd83-bb3dbd93d68c%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to puppet-users...@googlegroups.com
> <mailto:puppet-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/CAC76iT8KaMSw9ABBdx9StXtv_X%2BGRD8Z%3DLNBbfjmB5AK5Uhy%2Bg%40mail.gmail.com
> <https://groups.google.com/d/msgid/puppet-users/CAC76iT8KaMSw9ABBdx9StXtv_X%2BGRD8Z%3DLNBbfjmB5AK5Uhy%2Bg%40mail.gmail.com?utm_medium=email&utm_source=footer>.
signature.asc
Reply all
Reply to author
Forward
0 new messages