>
> But when I execute this from a server-client infrastructure it seems like
> the conditionals don't work They are not even processed:


Oh, they're processed just the same. But the key part that you've missed is
that the catalog is compiled on the *master*. That's where all functions
run. The catalog that the agents get is just a json file that describes
what state the system should be in. The reason it appeared to work when you
ran puppet apply was that apply operates like both master and agent in that
it compiles the catalog and then enforces it.

What's the use case you're trying to solve? Writing code that does
different things based on some arbitrary condition that might have
completely different results at different times is generally a brittle
anti-pattern. We generally want a catalog to manage a system with a known
end state.

On Fri, Jan 17, 2020 at 8:15 AM Joaquin Veira <joaquin.ve...@gmail.com>
wrote:

> Hi,
>
> I'm trying to use a condition based on the existance of a file. Something
> like this:
>
>     if find_file('/etc/if_this_file_exists') {
>         file { '/etc/create_this_file':
>             ensure => present,
>             owner  => 'root',
>             group  => 'root',
>             mode   => '0755',
>             source =>
> "puppet:///modules/${module_name}/etc/create_this_file",
>         }
>     }
>
> This is working correctly in a laboratory environment launched with:
>
> [root@labserver ~]# puppet apply --modulepath=/home/user/git/ -e "include
> my_module" --verbose --noop
> Info: Loading facts
> Notice: Compiled catalog for labserver in environment lab in 0.04 seconds
> Info: Applying configuration version '1579255663'
> Notice: /Stage[main]/my_module::Files/File[/...]/mode: current_value
> '0777', should be '0755' (noop)
> Notice: /Stage[main]/my_module::Files/File[/....]/mode: current_value
> '0777', should be '0755' (noop)
> Notice: /Stage[main]/my_module::Files/File[/...]/mode: current_value
> '0777', should be '0644' (noop)
> Notice: /Stage[main]/my_module::Files/File[/...]/mode: current_value
> '0777', should be '0770' (noop)
> Notice: /Stage[main]/my_module::Files/File[/...]/ensure: current_value
> 'absent', should be 'file' (noop)
> Notice: Class[my_module::Files]: Would have triggered 'refresh' from 5
> events
> Notice: Stage[main]: Would have triggered 'refresh' from 1 event
> Notice: Applied catalog in 0.12 second
>
> But when I execute this from a server-client infrastructure it seems like
> the conditionals don't work They are not even processed:
>
> [root@devserver ~]# puppet agent -tv --debug --noop
> ...
> Debug: /Stage[main]/previous_module::Install/File[/...]: Adding
> autorequire relationship with User[root]
> Debug: /Stage[main]/my_module::Files/File[/...]: Adding autorequire
> relationship with File[/etc/cron.daily]
> Debug: /Stage[main]/my_module::Files/File[/...]: Adding autorequire
> relationship with User[root]
> Debug: /Stage[main]/next_module::Config/App::Conf[00-syslog]/File[/...]:
> Adding autorequire relationship with User[root]
> ...
>
> Sorry I have to modify the output so I don't show the real paths & files.
>
> Can anyone explain to me why is this not working, please?
>
> Thanks & regards,
>
> JoaquĆ­n
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to puppet-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/a13df78f-e816-47e8-92d7-3cc46c316276%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/a13df78f-e816-47e8-92d7-3cc46c316276%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CACkW_L6d2NR-qpR1hg15ufWSNSrJZfBconn1WCt4N4bSUk_wKQ%40mail.gmail.com.

Reply via email to