Few questions about Puppet

84 views
Skip to first unread message

shazni nazeer

unread,
Oct 23, 2013, 6:11:08 AM10/23/13
to puppet...@googlegroups.com
Hi All,

I'm new to puppet and I've three requirements to achieve using puppet. 

1. I've a json file shown below that I need to modify, when I run my puppet script. 

{
    "assets":{

        "ignore":[],
        "icons":{
            "gadget":"icon-dashboard",
            "ebook" :"icon-ebook",
            "site" :"icon-site",
            "default":"icon-dashboard"
        }   
    }   
}

I need to add a new entry in the mid of "icons", say "aaaaa":"bbbbb". How do I do this?

2. I replace a directory using another directory. And I need to do the same after doing some other additions to configuration. I get the following error when I apply the 'file" resource twice.

Duplicate declaration: File[/home/shazni/Documents/Junk/wso2greg-4.6.0/samples/asset-models/ApplicationModel/] is already declared in file /home/shazni/.puppet/modules/gregstore/manifests/init.pp at line 85; cannot redeclare at /home/shazni/.puppet/modules/gregstore/manifests/init.pp:108 on node wso2-thinkpad-t530.private.wso2.com

My script does this.

    file { "$StoreHome/repository/deployment/server/jaggeryapps/store/extensions/assets/servicex":
        ensure => directory,
        recurse => true,
        purge => true,
        force => true,
        source => "puppet:///modules/gregstore/setup-beta2/store/servicex/",
    }  

  // Some more work 

    file { "$StoreHome/repository/deployment/server/jaggeryapps/store/extensions/assets/servicex":
        ensure => directory,
        recurse => true,
        purge => true,
        force => true,
        source => "puppet:///modules/gregstore/setup-beta2/store/servicex/",
    }  

How to solve this issue?

3. I want to run a script file, which in turn invoke some java class files. How to to do it in the same file?



Rahul Khengare

unread,
Oct 23, 2013, 7:43:08 AM10/23/13
to puppet...@googlegroups.com
Hi Shazni,


1. I've a json file shown below that I need to modify, when I run my puppet script. 

{
    "assets":{

        "ignore":[],
        "icons":{
            "gadget":"icon-dashboard",
            "ebook" :"icon-ebook",
            "site" :"icon-site",
            "default":"icon-dashboard"
        }   
    }   
}

I need to add a new entry in the mid of "icons", say "aaaaa":"bbbbb". How do I do this?

In this case you can explore the puppet augeas resource type. It will allow you to change the file contents.
But you have to learn the augeas tool format.
Refer,
  
 
2. I replace a directory using another directory. And I need to do the same after doing some other additions to configuration. I get the following error when I apply the 'file" resource twice.

Duplicate declaration: File[/home/shazni/Documents/Junk/wso2greg-4.6.0/samples/asset-models/ApplicationModel/] is already declared in file /home/shazni/.puppet/modules/gregstore/manifests/init.pp at line 85; cannot redeclare at /home/shazni/.puppet/modules/gregstore/manifests/init.pp:108 on node wso2-thinkpad-t530.private.wso2.com

My script does this.

    file { "$StoreHome/repository/deployment/server/jaggeryapps/store/extensions/assets/servicex":
        ensure => directory,
        recurse => true,
        purge => true,
        force => true,
        source => "puppet:///modules/gregstore/setup-beta2/store/servicex/",
    }  

  // Some more work 

    file { "$StoreHome/repository/deployment/server/jaggeryapps/store/extensions/assets/servicex":
        ensure => directory,
        recurse => true,
        purge => true,
        force => true,
        source => "puppet:///modules/gregstore/setup-beta2/store/servicex/",
    }  

How to solve this issue?
 
puppet does not allow you to perform operation on same file twice in manifests.
You have to do the all operations on single file in one file resource(Exactly once)  
 
3. I want to run a script file, which in turn invoke some java class files. How to to do it in the same file?

Transfer the script file to puppet agent/client using FILE resource and then use EXEC resource to execute that script file.
 
Hope this will help.

Thanks and Regards,
Rahul Khengare
NTT DATA OSS Center, Pune, India.

shazni nazeer

unread,
Oct 23, 2013, 8:28:39 AM10/23/13
to puppet...@googlegroups.com

Thank Rahul for your responses.

I would like to know how do I achieve my requirements. The second one seems a bit trickier

Rich Burroughs

unread,
Oct 24, 2013, 7:02:03 PM10/24/13
to puppet...@googlegroups.com
It's not clear to me exactly what you're trying to do. Unless I'm misreading something, both of those file resources are exactly the same. I'm not sure why you would need to manage the same resource twice with the same settings, but as the earlier person said, you can't.

Maybe part of the confusion comes from you thinking of manifests as scripts. They're not. With Puppet what you're doing is specifying what you want the running state of the system to be. And for a given resource, like a file, that's one state. And every time the agent runs, it will make sure the resource is in that state.

In fact by default Puppet may not do things in a given manifest in the order that they appear in the manifest, unless you do something specifically to control that. There's a doc on resource ordering here:

http://docs.puppetlabs.com/learning/ordering.html


Rich



--
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 post to this group, send email to puppet...@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.

shazni nazeer

unread,
Nov 11, 2013, 4:30:36 AM11/11/13
to puppet...@googlegroups.com
Hi Rich,

Thanks for the reply. May be I'm trying to do what puppet is not designed for. I had the requirement of replacing a directory with another directory and then run a script to test certain things with that directory content, and once that completed I wanted the same directory to be replaced with a completely different directory and run another script. The problem is how do I replace the same directory twice at two different times? That's why I told, this may not be achievable in puppet, because it's not designed to perform these sort of works.

thanks,

Shazni

jcbollinger

unread,
Nov 11, 2013, 9:22:18 AM11/11/13
to puppet...@googlegroups.com


On Monday, November 11, 2013 3:30:36 AM UTC-6, shazni nazeer wrote:
Hi Rich,

Thanks for the reply. May be I'm trying to do what puppet is not designed for. I had the requirement of replacing a directory with another directory and then run a script to test certain things with that directory content, and once that completed I wanted the same directory to be replaced with a completely different directory and run another script. The problem is how do I replace the same directory twice at two different times?


Puppet is not a script engine; it is a state management service.  You describe a target machine state to Puppet, and Puppet puts the machine into that state.  You cannot declare two different target states for the same physical resource because it does not make sense.  The longstanding system design in fact enforces a stronger constraint that you cannot declare the same resource twice, even with the same properties.

You cannot manage the same resource into two or more different states during the same Puppet run.  You could conceivably perform multiple runs, perhaps selecting which test to perform via tags, but at that point you have to consider why you are using Puppet for the job instead of some other system for which it is a more natural fit.

 
That's why I told, this may not be achievable in puppet, because it's not designed to perform these sort of works.



Oh, it's achievable.  At worst, you can write up a shell script that performs the whole job, including file manipulation, and have Puppet run it via an Exec resource.  I think, however, that you might be looking for an automated testing framework as your top-level system.  You could perhaps integrate Puppet into your system at a lower level, using it (say) on a per-test-case basis to set up your test fixtures.


John
 
Reply all
Reply to author
Forward
0 new messages