simple puppet script to copy files - puppet

Hi I'm new to puppet and trying to work on a sample to copy files from one location to another location. Any sample script to do that?
Ex: I've my file at d:\temp\test.txt and I want to copy this file to E:\mycopy\ folder.

You can "ensure" that the file at target location exists and provide the file to be copied as source in file type. A partial code snippet only showing relevant parts:
file { 'E:\mycopy\folder\filename':
ensure => present,
source => "d:\temp\test.txt",
}
Check the documentation of file type here and how source attribute behaves here. Now this will work with a few caveats :
If you are using absolute file path as source - then the file should be present on agent machine
If you are serving file from Puppet's file server then the source file should be in appropriate location in puppet's file server.
But what is your exact purpose? Similar thing can be achieved with content attribute of file type or other attributes

Related

Python - working with unkown directory name versions

I'm using python to download an application from a content distribution network. The application downloads as self extract file cabinet. When executed it creates a directory using a version naming format. For example app-version2/../app.exe, Thus I cannot rely on the folder name as it may change in the future. I'm trying to find the best way to work with the content inside the folder without depending on the actual folder name.
My idea was to rename the folder using os.listdir() and then os.rename(app-version2, myapp) This would work but is not automated. What would be the best automated method to find a folder name that contains version numbers and change that to something more static?
Assuming you want to find the path of the directory which begins with app, you can accomplish this using pathlib.Path:
from pathlib import Path
app_path = next(Path().glob('app*'))
This will give you the path to the first file or directory in your current directory whose name begins with "app".

Azure Logic App FTP Get File Content fails

I have set up a logic app with the ftp trigger [When a file is added or modified (properties only)]. This works just fine when I upload a 50+MB file to that ftp server. I have a [Get File Content] action set up right after the trigger. For the File input of the [Get File Content] action, I used the [List of Files Name] dynamic content from the trigger AND I have just filled in the path by using the available 'File Picker' (which connects to the FTP just fine). When I test this out, it fails on the [Get File Content] action stating BadRequest and this Body.
{
"status": 400,
"message": "An invalid request was made. Inspect the passed parameters and actions.\r\nclientRequestId: 7d9f2ff3-62d0-4f69-8cc5-f41c35297882",
"source": "ftp-eus.azconn-eus.p.azurewebsites.net"
}
The inputs that come into the action show the correct file name and path. So I am confused on what it means by "Inspect the passed parameters and actions". Can someone point me in the right direction on how to solve this?
EDIT
Here are some screenshots to show. I don't get [File Name] as a dynamic option from my trigger. It doesn't even matter though, I can pick the exact file I want downloaded from the FTP Picker and it still fails. See screenshots:
Dynamically select file:
Statically select file:
Same result from both of them:
If you use Get file content to pick file, you could find the input of File is the Path of the file you want, so you could not get the file content just with the File content. You could use File path or File name, if you want to use the File name you should also know the path.
If you want to use File name, the input would be like this, this is a little inconvenient.
Or just with the File path. Actually the inputs in these two ways are same, so they all could get the file.

how to access puppet variable in custom facts?

I am extracting a zip at a location, in extracted folder directory there is a install.jar.I want to copy a file to the directory where install.jar is available. Now the zip I am extracting may have different folder structure every time, because of this I can not use
file{'EXTRACTED_PATH/ant.properties':
ensure: present
}
So I wrote a custom fact that will find out path of a install jar & I accessed value in manifest like
$install_jar_location=$::getinstallerpath
Now in facts file I have to give path to search, this path I want to pass as a parameter.
for that I have declared one variable in manifest file
$installer_location="/home/oracle/Installer"
how can I access it in my custom fact.I tried to do following but $installer_locationvariable value is coming up blank.
Facter.add(:getinstallerpath) do
setcode do
Facter::Util::Resolution.exec("echo \"$(dirname \"$(find $installer_location -name \*install*.jar)\")\" ")
end
end

In Puppet using Hiera, where do I put the files I want to have installed on nodes?

I know puppet modules always have a files directory and I know where it's supposed to be and I have used the source => syntax effectively from my own, handwritten modules but now I need to learn how to deploy files using Hiera.
I'm starting with the saz-sudo module and I've read the docs but I can't see anything about where to put the sudoers file; the one I want to distribute.
I'm not sure whether I need to set up a site-wide files dir in /etc/puppetlabs/puppet and then make subdirs in there for every module or what. And does Hiera know to look in /etc/puppetlabs/puppet/files/sudo if I say, source => "puppet:///files/etc/sudoers" ? Do I need to add a pathname in /etc/hiera.yaml? Add a line - files ?
Thanks for any clues.
My cursory view of the puppet module, given their example of using hiera:
sudo::configs:
'web':
'source' : 'puppet:///files/etc/sudoers.d/web'
'admins':
'content' : "%admins ALL=(ALL) NOPASSWD: ALL"
'priority' : 10
'joe':
'priority' : 60
'source' : 'puppet:///files/etc/sudoers.d/users/joe'
Suggest it assumes you have a "files" puppet module. So under you puppet modules section:
mkdir -p files/files/etc/sudoers.d/
Drop your files in there.
Explanation:
The url 'puppet:///files/etc/sudoers.d/users/joe' is broken down thus:
puppet: protocol
///: Three slashes indicate the source of the file is in a module.
files: name of the module
etc/sudoers.d/users/joe: full path to the file within the module's "files" directory.
You don't.
The idea of a module (Hiera backed or not) is to lift the need to manage the whole sudoers file from you. Instead, you can manage each single entry in the sudoers file.
I recommend reviewing the documentation carefully. You should definitely not have a file { "/etc/sudoers": } resource in your manifest.
Hiera doesn't have to do anything with Files.
Hiera is like a Variables Database, and servers you based on the hierarchy you have.
the files inside puppet, are usually accessed in methods like source => but also these files are using some basic structure.
In most cases when you call an file or template.
A template can serve your needs to automatically build an sudoers based on that.
There are also modules that supports modifying sudoers too.
It is up to you what to do.
In this case, saz stores the location of the file in hiera, but the real location can be a file inside your puppet (like a module file or something similar).
Which is completely unrelated.
Read about puppet file server
If you have questions, just ask.
V

How can you specify the file name for a Log4net SmtpPickupDirAppender?

By default the SmtpPickupDirAppender appender creates a file without an extension. I can't find that there is a parameter (or other option) to configure the file extension.
The email service that picks up the file from the directory specified in the "pickupDir" parameter requires a file extension.
Is there a way to specify one?
Not built in.
From the source, it looks like it just creates a file name based on a guid and doesn't offer any configuration options,
filePath = Path.Combine(m_pickupDir, SystemInfo.NewGuid().ToString("N"));
writer = File.CreateText(filePath);
However, if you pull the source, it should be relatively straight forward to create your own appender that adds an file extension.

Resources