exec and variables

16 views
Skip to first unread message

Helmut Schneider

unread,
Dec 20, 2018, 11:56:10 AM12/20/18
to puppet...@googlegroups.com
Hi,

I want to exec something with a variable. If found the following link
and tried to implement:

https://stackoverflow.com/questions/33557093/puppet-notify-a-class-with-parameters

file { "${apacheConfPath}/conf-available/${file}":
mode => '0640',
owner => $rootUID,
group => $rootGID,
source =>
"puppet:///modules/my_apache/${operatingsystem}/${apacheConfPath}/conf.d/${file}",
# notify => a2enmod["$file"],
# notify => a2enmod['99-status.conf'],
}
exec { "a2enconf_${title}":
path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin',
refreshonly => true,
command => "a2enconf ${title}",
# subscribe => File['99-status.conf'],
subscribe => File["$file"],
}

Error: Failed to apply catalog: Could not find dependency
File[99-status.conf] for Exec[a2enconf_my_apache::config_files] at
/etc/puppetlabs/code/modules/my_apache/manifests/config_files.pp:130

Can someone point me to the right direction?

Thank you!

Ben Ford

unread,
Dec 20, 2018, 12:28:47 PM12/20/18
to puppet...@googlegroups.com
Sure. When you make a reference (the upper case File syntax), it has to point to a thing that exists. The reference is a resource type (File) and a resource title (99-status.conf), but you've not defined a resource with that title. Basically, it's like making a symlink to a file that doesn't exist. To fix it, you just need to change your code so the reference and the resource title agree on a title.


--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/xn0lixerc48gqno000%40news.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Helmut Schneider

unread,
Dec 21, 2018, 4:43:18 AM12/21/18
to puppet...@googlegroups.com
Ben Ford wrote:

> Sure. When you make a reference (the upper case File syntax), it has
> to point to a thing that exists. The reference is a resource type
> (File) and a resource title (99-status.conf), but you've not defined
> a resource with that title. Basically, it's like making a symlink to
> a file that doesn't exist. To fix it, you just need to change your
> code so the reference and the resource title agree on a title.
>
> Read more about relationships at
> https://puppet.com/docs/puppet/5.5/lang_relationships.html and about
> the reference syntax at
> https://puppet.com/docs/puppet/5.5/lang_data_resource_reference.html

That helped, thanks:

$filesConfd0640 = [
"99-status.conf",
]
$filesConfd0640.each |String $file| {
file { "${apacheConfPath}/conf-available/${file}":
mode => '0640',
owner => $rootUID,
group => $rootGID,
content => epp("${module_name}/etc/apache2/conf.d/${file}.epp",
{ apacheCfg => $apacheCfg, apacheConfPath => $apacheConfPath }),
notify => Exec['/usr/local/bin/apache.sh -c restart']
}
exec { "a2enconf ${file}":
path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin',
refreshonly => true,
command => "a2enconf ${file}",
subscribe => File["${apacheConfPath}/conf-available/${file}"],
}
}

Reply all
Reply to author
Forward
0 new messages