Create folder and install software using puppet - puppet

Suppose I have a vm running on my pc. My vm has puppet installed. Now I want to install firefox on my pc not in my vm. I know to install firefox I can just do sudo apt-get install firefox on my pc but I want to run this command from my vm using puppet. How can I do that? or can I do something like (code below is just an idea if something like this is possible?)
package { 'firefox':
ensure => 'present',
provider => '....',
}
Also I want to create a folder 'test' in my pc. Again I can do this by running commands cd ~ and sudo mkdir test. But I want to create the folder using puppet. How can I do this?

Yes that's exactly how you install a package, also to create a directory you will need to do something like this: file { '/your/dir/path': ensure => directory, }
Moreover, this 2 resources may take additional parameters for example the file resource might have an owner or some permissions assigned to it which will look something like:
file { '/your/dir/path':
ensure => directory,
owner => root,
mode => 700,
}

Related

"Docker context ls" and "sudo docker context ls" don't have same setting options

I am a docker newbie. I just installed Docker and Docker Desktop as per offical instruction. Soon, I start to have problem like: the Docker Desktop does not show container. I think it's because I haven’t set the contexts same for with and without sudo privilege, according to this post.
But I don’t understand why I only have the “default” option for “sudo docker context ls”. Please help me on this. Many thanks!
OS:Ubuntu 20.04.5 LTS
screenshot
The docker context data is stored in the user's home directory. When you use sudo, that changes users and home directories. Without sudo it might look in /home/yourname/.docker/contexts, but when you switch to root with sudo it also changes home directories and looks in /root/.docker/contexts.
You do not need Docker Desktop on native Linux. Installing Docker (what the Docker documentation now calls "Docker Engine") through your OS's package manager is sufficient. If you are on a single-user system, you can grant your ordinary user access to the Docker socket, but be aware that it's all but trivial to use this access to root the entire host.
When you do uninstall Docker Desktop, there are additional files in your home directory you need to remove
rm -rf $HOME/.docker/desktop
$EDITOR $HOME/.docker/config.json
# and remove `credsStore` and `currentContext`
Once you've done this cleanup, you'll revert to Docker's default behavior of using the $DOCKER_SOCK environment variable, or without that, /var/run/docker.sock. That system-global Docker socket file is the same regardless of which user you are, and it won't be affected by sudo.

Find file(s) in a directory on the node by pattern in Puppet

How can I find a file in a directory on the node by using shell-patterns or regex?
What I want to do:
I download a tar file to /tmp/myfiles on the appropriate client and unpack this archive. From it come several deb files (about 10 of them). The filenames change with time, because there are version numbers integrated in the name.
The file names looks like:
package1_8.0-22.65.linux.x86_64.deb
package2_6.5-23.89.linux.x86_64.deb
I need to identify some of them (not all) to be able to install them via package with provider => dpkg.
The packages (like package1, package2) do not occur multiple times with different version numbers, so matching could be done easily without having to compare version numbers:
Shell pattern: package1_*.linux.x86_64.deb
Regex: ^package1_.+\.linux\.x86_64\.deb$
Is there a command or module in Puppet to find files by match pattern in a directory?
Or can I grab the result of exec with command => "ls /tmp/myfiles/..." and evaluate it?
Supposing that you mean that the tar file is downloaded as part of the catalog run, what you describe is not possible with Puppet and its standard Package resource type. Keep in mind the catalog-request cycle:
The client gathers node facts.
The client submits a catalog request bearing the gathered facts.
The server uses the node's identity and facts, the manifests of the appropriate environment, and possibly the output of an external node classifier to build a catalog for the client.
The client applies the catalog.
To create Package resources during step (3), Puppet needs to know at least the names of the packages. As you describe it, the names of the packages cannot be determined until step (4), which is too late.
You could have Puppet use the packages downloaded on a previous run by defining a custom fact that gathers their names from the filesystem, but that's risky and failure prone.
I think the whole endeavor is highly suspect and likely to cause you trouble. It would probably be better to put your packages in a local repository at your site and use either node data or a metapackage or both to control which are installed. But if you insist on downloading a tar full of DEBs, then unpacking and installing them, then your best bet is probably to use an Exec for the installation. Something like this:
# Ensure that the TAR file is in place
file { ${download_dir}:
ensure => 'directory',
# ...
}
file { "${download_dir}/packages.tar":
ensure => 'file',
# ...
}
-> exec { 'Install miscellaneous DEBs':
path => ['/bin', '/usr/bin', '/sbin', /usr/sbin'],
command => "rm '${download_dir}'/*.deb || :; tar xf '${download_dir}'/packages.tar && apt-get install '${download_dir}'/*.deb",
provider => 'shell',
}

Installing Tomcat as different user using yum

I'm installing tomcat using yum package manager, but I want to run the service under different user (not tomcat).
Is there an easy way to do that on installation or am I always forced to change owner of all directories, service etc.?
If tomcat is managed by systemd, you can add a custom file /etc/systemd/system/tomcat.service.d/custom-user.conf containing just the following lines
[Service]
User=myUser
For older OSes you should be able to do it by setting the TOMCAT_USER variable in /etc/sysconfig/tomcat.
This is an extra configuration of course. It's not possible to modify a rpm-provided configuration file without rebuilding the rpm. If you have an internal yum repository you can build a rpm package providing this file but I think the easier way is using a configuration management tool like ansible or saltstack.

replace m2 file on ububtu server 18.04

I install the Apache Maven on Ubuntu server with Apt with sudo apt install maven
I am new to Linux but as I am understanding this installation produces an m2 repository.
what is want is the following:
first how to find and inspect this m2?
second how to replace this m2 with an m2 repository that I have download to my desktop?
By default, maven's local repository is located in the user's home directory. In fact it's actually named ".m2" directory, instead of just "m2". It is a hidden directory. If you are not in your home directory, issue "cd ~" first. Then issue "ls -al" to see the presence of .m2 directory.
If for any reason, you do not see that "m2" directory after issuing above command, it simply means that you did not built or run any project that requires maven to get triggered and create that .m2 folder.
ps: Replacing the existing .m2 folder with the one you have on your desktop may not be a good idea. Instead, simply run the project (that you think requires the needed dependencies). This will build the .m2 directory afresh along with everything that app needs.

Installing software on server machine - the install process wants to modify root folders which I cannot access

I'm configuring software on my first web server, so I am not totally familiar with how everything works, but here is the basic problem:
I have purchased hosting on a web server that runs on CentOS. I have been able to install postgreSQL via an install process that the hoster provides, so that my database will be local only to my home folder. That is working fine.
However, I am trying to install a postgreSQL extension called PostGIS. I have tried to compile it from source on my web server, but it now requires an additional library called GEOS. I downloaded the library from http://download/osgeo.org/geos/geos-3.6.2.tar.bz2, extracted it, and used make install to run it.
Now the problem is that it fails due to this error:
/bin/mkdir: cannot create directory /usr/local/include/geos: Permission Denied
It's not really a surprise, because it is trying to make a new directory in the system root folders, rather than within my personal home folder, which is the only one I have access to. I can't think of any other way around this. Am I just unable to install this library? Or can I "trick" it somehow into installing in in my home directory, where I have full admin rights?
I think You need to execute a command with root user privileges.
Because, make install command need root user privileges.
Like,
sudo make install
or with root user. Like,
sudo su
make install

Resources