0

I want to move files by extension.

1) Do I really have to create the files and delete after the copy or can I do that in a single task?

2) What if I want to copy *.jpg files to folder files/jpg/ and *.htm files to files/htm? How can I do that?

Thanks!

1 Answer 1

2

I want to move files by extension.

Although Puppet can help you do this, it is not what Puppet is designed for. Puppet provides a machine-state management service. Everything it does should be construed in the context of this decision tree:

  • What is the desired target state?
  • Is the machine already in the target state?
    • Yes: do nothing.
    • No: update the machine to be in the target state

Puppet is not a script engine, and Puppet manifests should not be regarded as scripts.

1) Do I really have to create the files and delete after the copy or can I do that in a single task?

No and yes, respectively. Although Puppet is not a script engine, it can execute arbitrary programs (including scripts) and shell commands for you. This is provided via the core Exec resource type. This will work best for you if you conceptualize your task in terms of a target state -- as opposed to a desired action -- and write your code from that perspective, but you should be able to proceed even if that seems obscure.

2) What if I want to copy *.jpg files to folder files/jpg/ and *.htm files to files/htm? How can I do that?

How would you do it from the command line? Notwithstanding the conceptualization issue, the nuts and bolts are that you would apply an Exec resource whose command parameter is a shell command that does the job, either directly or via a script.

Or if you succeeded in couching the objective in terms of a resource to be managed into a specific state, and you were an overachiever with time on your hands, then you might consider encapsulating that in a custom resource type, an instance of which you could use in place of a generic Exec.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.