Ask Your Question
0

how does class contain work? (to set up yum repos before install rpms)

asked 2016-06-13 05:04:02 -0500

woosley gravatar image

updated 2016-06-13 09:46:08 -0500

so I want to setup the yum repos first before I install any rpm packages, I don't want to add some requires in the package resource, so I am thiking about using contain. Here is the sample code

[root@maddog x]#  cat profile/manifests/test.pp
class profile::test {
  include profile::ngnix
  include profile::base
  Class['profile::base'] -> Class['profile::ngnix']
}

[root@maddog x]#  cat profile/manifests/ngnix.pp
class profile::ngnix {
  contain ::ngnix
}
[root@maddog x]#  cat profile/manifests/base.pp
class profile::base {
  contain repo::withproxy
}

this setup suppose to setup repo::withproxy before nginx is installed. but when I run puppet, it is not the case, see output below

[root@maddog x]# puppet apply -v -d --modulepath ./ -e 'include profile::test'

........
Info: Applying configuration version '1465812031'
Notice: /Stage[main]/Repo::Pre/File[/etc/yum.repos.d/readme.txt]/ensure: defined content as '{md5}6e1bd1543e9afba17699e4319f5ded0b'
Debug: /Stage[main]/Repo::Pre/File[/etc/yum.repos.d/readme.txt]: The container yum_repos_d will propagate my refresh event
Info: yum_repos_d: Scheduling refresh of Exec[yum_clean]
Debug: yum_repos_d: The container Class[Repo::Pre] will propagate my refresh event
Debug: Prefetching yum resources for package
Debug: Executing '/bin/rpm --version'
Debug: Executing '/bin/rpm -qa --nosignature --nodigest --qf '%{NAME} %|EPOCH?{%{EPOCH}}:{0}| %{VERSION} %{RELEASE} %{ARCH}\n''
Debug: Executing '/bin/rpm -q nginx --nosignature --nodigest --qf %{NAME} %|EPOCH?{%{EPOCH}}:{0}| %{VERSION} %{RELEASE} %{ARCH}\n'
Debug: Executing '/usr/bin/yum -d 0 -e 0 -y list nginx'
Error: Execution of '/usr/bin/yum -d 0 -e 0 -y list nginx' returned 1: Error: No matching Packages to list
Error: /Stage[main]/Ngnix/Package[nginx]/ensure: change from absent to present failed: Execution of '/usr/bin/yum -d 0 -e 0 -y list nginx' returned 1: Error: No matching Packages to list
Notice: /Stage[main]/Repo/Repo::Yumrepo[nginx]/File[/etc/yum.repos.d/nginx.repo]/ensure: defined content as '{md5}56b0832c7af04b058a111e3d3ec571c0'
Info: /Stage[main]/Repo/Repo::Yumrepo[nginx]/File[/etc/yum.repos.d/nginx.repo]: Scheduling refresh of Exec[yum_clean]
Debug: /Stage[main]/Repo/Repo::Yumrepo[nginx]/File[/etc/yum.repos.d/nginx.repo]: The container Repo::Yumrepo[nginx] will propagate my refresh event
Debug: Repo::Yumrepo[nginx]: The container Class[Repo] will propagate my refresh event
Notice: /Stage[main]/Repo/Repo::Yumrepo[node]/File[/etc/yum.repos.d/node.repo]/ensure: defined content as '{md5}17aff07773ea768

apparently it is installing nginx before yum repo files are configured, what did I do wrong here? I am using puppet-3.7.4-1.el6.noarch, I have the sample puppet code at here

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-06-14 03:05:31 -0500

woosley gravatar image

I will try to answer myself after many tries. There are 2 things to note here

  • contain only works for resources under that class, if there is again another subclass in the contained class, you will have to contain the subclass again.
    • contain does not work on realized resources.
edit flag offensive delete link more
0

answered 2016-06-13 11:34:49 -0500

DarylW gravatar image

updated 2016-06-13 11:37:50 -0500

So, by looking at your output, I assume you are managing your yumrepo manually as files. Have you tried using the built in yumrepo type? You could use the spaceship operator to ensure some rough ordering (assuming you don't use any packages to set up your repos)

If you did, you could do something like the following to make sure they are all set up before any packages.

Yumrepo<| |> -> Package<| |>

You could also use similar notation in your custom repo for ordering.


Ah, I tried to solve your problem without answering your question... how does containment work?

https://docs.puppet.com/puppet/latest...

Containment is a little bit odd, and it is easy for individual resources to not behave how you would expect.

For a more specific response to how it behaves in the roles/profiles pattern, check out this other answer.. https://ask.puppet.com/question/18868...

edit flag offensive delete link more

Comments

I do not want to use spaceship operator because what about other dependencies? maybe in the future I will need other stuff like network setup, mount share folders before i can install anything, the cleanest way I am thinking about is just using contain and group all those resources into one class

woosley gravatar imagewoosley ( 2016-06-13 21:15:18 -0500 )edit

then I can order then effectively, but it is not working as expected :(

woosley gravatar imagewoosley ( 2016-06-13 21:16:38 -0500 )edit

Understood. Understanding containment is important, but the specific ordering of apt/yum repos with packages does come up quite often, and sometimes not in a way that fits nicely in a pair of classes.

DarylW gravatar imageDarylW ( 2016-06-16 07:36:15 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-06-13 05:04:02 -0500

Seen: 74 times

Last updated: Jun 14 '16