How do i use yumrepo in Puppet to add the Docker repos? - puppet

Per the Docker documentation, the list of yum repositories are added by this command:
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
I'd like to have Puppet do this for me, so I was hoping this would work:
yumrepo { "docker":
descr => 'docker',
baseurl => 'https://download.docker.com/linux/centos/docker-ce.repo',
enabled => 1
}
But, this doesn't work.
Unfortunately, the URL used in the yum-config-manager contains an entire list of name/baseurl/enabled/gpgcheck/gpgkey entries, where the yumrepo is expecting just one of those. So, is there a way to add the entire list of entries in the docker URL with one yumrepo command, or some other command?

The URL in the Docker instructions is that of a .repo file to be installed on the system. The contents of such a file are what the properties of a Yumrepo resource describe. Applying a Yumrepo resource involves managing the contents of repository description files, not obtaining external files from somewhere else, whether via yum-config-manager or otherwise.
You have many options, but here are some of the more likely ones:
Obtain the specified file from docker.com, store it in your module's files directory, and install and manage it on target nodes via a File resource.
Install the repo file on some node that also has Puppet, and use the puppet resource command to obtain Puppet DSL representations of the Yumrepo resources that result. Put these into a suitable class on the master.

Or alternatively you can peak inside docker-ce.repo and write proper yumrepo config:
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://download.docker.com/linux/centos/$releasever/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
into:
yumrepo { 'docker-ce-stable':
name => 'Docker CE Stable',
baseurl => 'https://download.docker.com/linux/centos/$releasever/$basearch/stable',
enabled => 1,
gpgcheck => 1,
gpgkey => https://download.docker.com/linux/centos/gpg',
}
which looks straightforward and could be generated once from docker-ce.repo file via sed or other tools.

Related

How to provide a startup service file in Puppet

We have RedHat 7.2 Linux OS and use puppet to perform our tasks. I am using puppet to install some software, which has worked fine and now the final step is to create an OS level service. In earlier versions of RHEL, we used chkconfig but that has been replaced with systemctl. Of course, the recommended way of performing this task is using a service. Since this is a custom software, I have my own startup script that I usually copy over to /etc/init.d, run chkconfig and then startup the service. How do I perform these tasks via Puppet for RedHat 7.2 OS ? I only want to create the service (not start it up or anything). This way, when the server reboots, the service will startup the app.
EDIT :
#redstonemercury for RHEL 7 I would think the following would be required. But your suggestion definitely helps as I was thinking along the same lines.
https://serverfault.com/questions/814611/puppet-generated-systemd-unit-files
file { '/lib/systemd/system/myservice.service':
mode => '0644',
owner => 'root',
group => 'root',
content => template('modulename/myservice.systemd.erb'),
}~>
exec { 'myservice-systemd-reload':
command => 'systemctl daemon-reload',
path => [ '/usr/bin', '/bin', '/usr/sbin' ],
refreshonly => true,
}
In puppet, use a package resource to install the package (assuming it's in repos that you're declaring already), then use a file resource to declare the /etc/init.d file, and put require => Package[<package_resource_name>] as a parameter in the file declaration to ensure the custom file gets created after the package has installed (so doesn't potentially get overwritten by the package's /etc/init.d file). E.g.:
package { 'mypackage':
ensure => present,
}
file { '/etc/init.d/mypackage':
ensure => present,
content => template('mypackage/myinitd'),
require => Package['mypackage'],
}
This is if you want to use a template. For a file, instead of content use source: source => puppet://modules/mypackage/myinitd

Puppet: making .yaml dependent on .pp

I am trying to install docker onto a disk other than system on my CentOS 7.2 VM. I create a directory and a symlink first with the required target in my .pp, and then want to install docker using yaml.
file { '/data/docker-latest':
ensure => 'directory',
}
file { '/var/lib/docker-latest':
ensure => 'link',
target => '/data/docker-latest',
require => File['/data/docker-latest'],
}
For it to work, the directory and the symlink need to be created before the .yaml kicks in:
packages:
docker-latest:
ensure: installed
services:
docker-latest:
ensure: running
But there is no guarantee like this. Is there a way I can make my .yaml code to require => File['/var/lib/docker-latest']?
Or am I better off installing and running docker inside .pp?

add repo key using puppet under ubuntu

I'll need to add a apt repository key to a bunch of ubuntu hosts using puppet.
Would a statement like this work for that?
exec {"add apt key for elastic":
command => "/usr/bin/curl https://packages.elasticsearch.org/GPG-KEY-elasticsearch | /usr/bin/apt-key add -",
}
thanks
Yes, this should work but this will also apply the same configuration whenever you rerun Puppet.
From exec docs:
Any command in an exec resource must be able to run multiple times without causing harm — that is, it must be idempotent. There are three main ways for an exec to be idempotent:
The command itself is already idempotent. (For example, apt-get update.)
The exec has an onlyif, unless, or creates attribute, which prevents Puppet from running the command unless some condition is met.
The exec has refreshonly => true, which only allows Puppet to run the command when some other resource is changed. (See the notes on refreshing below.)
I try and only use execs if I really have to. One of the reasons being that you have to code the exec so that it only runs when you want to. Instead, you can use the apt module. This will only place the key on the host if it does not already exist. The resource is under puppet control so will not be added on subsequent runs:
include apt
apt::key { 'elasticsearch':
id => '46095ACC8548582C1A2699A9D27D666CD88E42B4',
options => 'https://packages.elasticsearch.org/GPG-KEY-elasticsearch',
}

puppet giving class is not found

I was trying to write a module for epel repo.
here is the content of that module.
[root# manifests]# cat init.pp
class epel {
file { "/etc/yum.repos.d/epel.repo":
ensure => "present",
mode => "400",
owner => "root",
group => "root",
source => "puppet://$puppetmaster/modules/yumrepos/files/epel.repo"
}
}
While applying this module to client side, I am getting following error.
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not find class epel for
Please tell me where will be the error exists.
Thanks in adv
Sankar
The class epel will only be located if the init.pp file is in the epel module.
Make sure that
The file is in the manifests subdirectory
The epel tree (including manifests/) is in a module search directory of the current environment
There is no other epel module (this is pretty far fetched, though)
Note that you probably want to use the yumrepo type to manage repositories, instead of deploying prepared configuration files.

Whats the best approach to create a repo of the installers to be used for installing and upgrading in the puppet managed nodes

Lets take the example, I am having a jboss-4.2.3 installers as a .tar file. In general to install jboss, i ll
1. untar the jboss-4.2.3 into a prefefined folder (opt/server/jbossas/) into multiple servers
2. untar the openjdk into a preferined path (/opt/software/java)set the path in the bash.profile
3. Create server profile in the place where jboss is installed
4. Start the server.
Lets say that I have to do this in 16 nodes (servers).
Now, I should store the jboss and openjdk installers at a central location and it should be transferred to the nodes before the 1st step can begin.
I wrote the manifest to perform the requirements form 1 to 4. But not sure how can I automate the transfer of the installers from a central repo. I am not worried about the type of central repo. It can be a ftp or puppet or anything else.
Please help me. I was going through filebucket. Will this help or should i write a manifest to get this file from a ftp server?
How to create a file repo which can be referred in puppet manifests?
I am not sure about your exact problem, but you can have a look at this and get an idea...
In most of the usage the files are transferred from the puppetmaster to the clients. If you have your policies defined in a module to untar and install the packages, e.g. module name jboss, you can keep the tarball in these kind of structure in the puppet master and run puppet agent from puppet client :
/etc/puppet/module/jboss/files/jboss_pkg.tar
Your policy for your clients should then say something like the following in the :
In e.g,
/etc/puppet/modules/jboss/manifests/init.pp
class jboss {
file { '/tmp/installation/jboss_pkg.tar' :
source => "puppet:///modules/jboss/jboss_pkg.tar",
}
#You can then right a small script that will execute all the installation process. You can use 'exec' in puppet to do that.
exec { 'install_jboss' :
command => "/path/to/install_jboss.sh",
require => File["/tmp/installation/jboss_pkg.tar"],
onlyif => "/check/that/it/is/not/installed/already",
}
## and write other execs to start the server or enable services etc...
}
# In site.pp
node 'client.mytest.org' {
include jboss
}
The general solution to provide installers to Puppet is to set up your own package repository (rather than just a file repo).
http://www.techrepublic.com/blog/opensource/create-your-own-yum-repository/609
Then, you can use Puppet's built in package resource for easy install/upgrade/uninstall
http://docs.puppetlabs.com/references/latest/type.html#package
The following projects seem to provide a rpm/deb version of JBoss that you can publish to your repository
https://github.com/floreal/jboss-deb-package
http://code.google.com/p/jboss-rpm/

Resources