Re: [Puppet Users] how to use external facts in a template?

2017-01-25 Thread Sans
Hi Henrik,

Thanks for commenting. Could you elaborate "Only reference Facter in logic 
that implements facts" pls? Does it mean when defining, e.g. a custom-fact, 
it's okay to reference another fact but not anywhere else? People gave me 
so many advice about dos and don'ts but no one actually explain why it's 
not working or how can I do it. Regardless of it should be done or not, why 
it works for thing like *Facter.value(:hostname)* but not with like: 
*Facter.value(:my_external_fact)*?

Basically, I have some external facts setup, during the initial machine 
provisioning and then I wanna make sure those facts are defined, if not put 
those facts in the external_fact file with some default value. That 
template is to maintain that external_fact file - that's my case.

-San

On Wednesday, January 25, 2017 at 11:23:06 PM UTC, Henrik Lindberg wrote:

>
> Do not ever reference Facter directly on the master side from functions 
> or ERB templates used when compiling. Only reference Facter in logic 
> that implements facts. It should be safe to reference Facter on the 
> agent side in provider logic. 
>
> If you have been advised to use Facter directly in templates I would 
> like to know where that advice came from. 
>
> You want to reference @facts['factname'] in an ERB if you are on a 
> modern puppet, otherwise individual top scope variables. 
>
> - henrik 
>
>
> -- 
>
> Visit my Blog "Puppet on the Edge" 
> http://puppet-on-the-edge.blogspot.se/ 
>

-- 
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/e45d81c5-f66a-4c29-960b-c52cbc334486%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Puppet Users] how to use external facts in a template?

2017-01-25 Thread Henrik Lindberg

On 25/01/17 20:20, Sans wrote:



On Wednesday, January 25, 2017 at 7:05:03 PM UTC, R.I. Pienaar wrote:



only if you enable structured facts and have a new facter


Well, it's not "structured" i.e. it returns only a string. and didn't
work as expected.
It also an "external fact", not sure if that's the main issue.
Facter.value() works fine with other  fact, like "hostname" etc.


Do not ever reference Facter directly on the master side from functions 
or ERB templates used when compiling. Only reference Facter in logic 
that implements facts. It should be safe to reference Facter on the 
agent side in provider logic.


If you have been advised to use Facter directly in templates I would 
like to know where that advice came from.


You want to reference @facts['factname'] in an ERB if you are on a 
modern puppet, otherwise individual top scope variables.


- henrik


--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

--
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/88bb5bc6-bb64-e8e2-80b6-97fa6b2a81db%40puppet.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Puppet Users] how to use external facts in a template?

2017-01-25 Thread R.I.Pienaar




On Wed, Jan 25, 2017, at 08:20 PM, Sans wrote:

> 

> 

> On Wednesday, January 25, 2017 at 7:05:03 PM UTC, R.I. Pienaar wrote:
>> 

>> 

>> only if you enable structured facts and have a new facter 

> 

> Well, it's not "structured" i.e. it returns only a string. and didn't
> work as expected.
> It also an "external fact", not sure if that's the main issue.
> Facter.value() works fine with other  fact, like "hostname" etc.
> 



regardless, for @facts to exist you have to enable that feature.  It's
not about *your specific fact*

-- 
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/1485372233.3876307.859509952.4C8BA71C%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Puppet Users] how to use external facts in a template?

2017-01-25 Thread Sans


On Wednesday, January 25, 2017 at 7:05:03 PM UTC, R.I. Pienaar wrote:
>
>
>
> only if you enable structured facts and have a new facter 
>

Well, it's not "structured" i.e. it returns only a string. and didn't work 
as expected. 
It also an "external fact", not sure if that's the main issue. 
Facter.value() works fine with other  fact, like "hostname" etc.

-San 

-- 
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/8ca3bbac-e3ff-4fc6-9af5-6c27b6506d07%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Puppet Users] Contributor Summit EU Feb. 8 - after ConfigMgmt Camp

2017-01-25 Thread Meg Hartley
Hi Folks,

You're invited to Contributor Summit EU on 8 February, the day after 
ConfigManagement Camp in Ghent. It's a great opportunity to work with other 
Puppet folks and add more learning to your ConfigMgmt Camp experience. 

Registration and more 
information: https://contributor-summit-eu-2017.eventbrite.com

I'm happy to answer any questions.

See you there,
Meg
Puppet Community team

-- 
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/e4a0cea5-1916-4d15-9e9f-a43f7f06cae3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Puppet Users] how to use external facts in a template?

2017-01-25 Thread R.I.Pienaar


- Original Message -
> From: "Sans" 
> To: "puppet-users" 
> Sent: Wednesday, 25 January, 2017 20:01:20
> Subject: Re: [Puppet Users] how to use external facts in a template?

> On Wednesday, January 25, 2017 at 2:20:30 PM UTC, R.I. Pienaar wrote:
>>
>>
>> not been following, but if you're on a recent version @facts["foo"] is the
>> best
>>
> 
> I didn't know that but will check soon. I'm on v3.8.x - will it work there?

only if you enable structured facts and have a new facter

-- 
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/1509158760.495323.1485371092938.JavaMail.zimbra%40devco.net.
For more options, visit https://groups.google.com/d/optout.


Re: [Puppet Users] how to use external facts in a template?

2017-01-25 Thread Sans


On Wednesday, January 25, 2017 at 2:20:30 PM UTC, R.I. Pienaar wrote:
>
>
> not been following, but if you're on a recent version @facts["foo"] is the 
> best 
>

I didn't know that but will check soon. I'm on v3.8.x - will it work there?

-S

-- 
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/252c5111-bac6-4147-ac49-3423624a3b58%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Puppet Users] Re: Using notify with concat module...

2017-01-25 Thread Sean
Thank you for the reply!

On Tuesday, January 24, 2017 at 4:42:10 AM UTC-5, Luke Bigum wrote:
>
>
>
> On Monday, 23 January 2017 20:55:44 UTC, Sean wrote:
>>
>> Hello,
>>
>> I was reading over several threads regarding the use of concat modules 
>> and subscribe capabilities.  It seems everyone is subscribe from another 
>> resource instead of notify with a concat resource.  My preference is to use 
>> notify, as I think it makes the code read better for documentation 
>> purposes.  One thread implied that subscribe and notify are interchangeable 
>> as long as refreshonly=true.  Is that correct in the case of using notify 
>> with concat?  Is it sufficient to use one notify statement inside the main 
>> concat resource for a file, or do I need to notify from each 
>> concat::fragment resource?  I am hoping someone can clear up a bit of 
>> confusion I've developed reading through the threads.  
>>
>
> There should be no difference, the examples you've seen are probably 
> written by someone with a mental model where 'subscribe' makes more sense, 
> where you and I think 'notify' reads better.  The one time where it might 
> get cumbersome is if you have one Concat resource that has to notify dozens 
> of other resources, so the Notify parameter ends up being a large array of 
> resources.  In that case the code might read better to put one Subscribe on 
> each other resource, but that's personal preference.
>
> I would not recommend you put your own requirements on concat::fragments, 
> just let the Concat module sort out it's own dependencies. You can easily 
> create loops, even through implicit relationships that aren't immediately 
> obvious. For example here's two classes, one that manages the Gnome dconf 
> file and one of my own that sets some of the settings I want, but I've 
> decided I need dconf done first before the my_desktop class is finished:
>
> *
> $dconf_file = '/tmp/dconf'
> class my_desktop {
>   concat::fragment { 'setting1':
> target => $dconf_file,
>   }
>   service { 'some_stuff': }
> }
>
> class dconf {
>   concat { $dconf_file: }
> }
>
> include dconf
> include my_desktop
>
> Class[dconf] -> Class[my_desktop]
> *
>
> That doesn't work so well.
>
>
>
>> For background, I'm using puppet to configure Gnome using dconf.  I've 
>> written a simple Exec resource that runs dconf-update, refreshonly => true. 
>>  A concat resource might manage a file that collects several Gnome options 
>> that relate to each other, where each concat::fragment resource corresponds 
>> to a single Gnome option...like a fragment for enabling the screensaver, 
>> and another fragment for the idle-delay.  If the file is updated, 
>> dconf-update needs to be run and should only be run once at the end of a 
>> puppet run.
>>
>> Thanks for your thoughts.
>>
>

-- 
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/78e3f373-59ad-47da-94b4-7732320623b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Puppet Users] how to use external facts in a template?

2017-01-25 Thread R.I.Pienaar


- Original Message -
> From: "Sans" 
> To: "puppet-users" 
> Sent: Wednesday, 25 January, 2017 15:17:19
> Subject: Re: [Puppet Users] how to use external facts in a template?

>> Hi Sans,
>>
>> I think your ERB syntax may be off. Here's an example doing something
>> similar. Instead of Facter.value() just put an @ in front of the fact
>> name.
>>
>> <% @nameservers.each do |nameserver| -%>
>> nameserver <%= nameserver %>
>> <% end -%>
>>
>> Best regards,
>> -g
>>
>>  
> AFAIK (and understand), when you gave this: @nameservers compiler just
> treat that as variable, regardless of the fact it's actually a Fact or
> otherwise. Facter.value() is a valid syntax, which I use very often in my
> template and custom fact. The part of template, also try to determine if
> the fact is defined at all or not. It's not working for any external fact.
> As I already mentioned, it works for other facts, like "hostname" etc.
> 

not been following, but if you're on a recent version @facts["foo"] is the 
best

-- 
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/788926786.267818.1485354014084.JavaMail.zimbra%40devco.net.
For more options, visit https://groups.google.com/d/optout.


Re: [Puppet Users] how to use external facts in a template?

2017-01-25 Thread Sans


> Hi Sans, 
>
> I think your ERB syntax may be off. Here's an example doing something 
> similar. Instead of Facter.value() just put an @ in front of the fact 
> name. 
>
> <% @nameservers.each do |nameserver| -%> 
> nameserver <%= nameserver %> 
> <% end -%> 
>
> Best regards, 
> -g 
>
>  
AFAIK (and understand), when you gave this: @nameservers compiler just 
treat that as variable, regardless of the fact it's actually a Fact or 
otherwise. Facter.value() is a valid syntax, which I use very often in my 
template and custom fact. The part of template, also try to determine if 
the fact is defined at all or not. It's not working for any external fact. 
As I already mentioned, it works for other facts, like "hostname" etc.

-S
 

-- 
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/c31d4411-f70d-44e9-8441-713c6ce23338%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Puppet Users] how to use external facts in a template?

2017-01-25 Thread Garrett Honeycutt
On 1/25/17 6:43 AM, Sans wrote:
> Dear all,
> I'm having this issue and running out of ideas.
> I have this two external facts (defined in
> /etc/facter/facts.d/extn_git_facts.txt):
> 
> |
> 
> root@p19-d-pmaster-001:~# facter|grep ks_git
> ks_git_puppet-hiera =>master
> ks_git_puppet-master =>develop
> |
> 
> I want to use these two facts in a template. Here is my pseudo code:
> |
> 
> <%-
> git_repos =['puppet-hiera','puppet-master']
> git_repos.each do|g_repo|
> git_branch ="ks_git_#{g_repo}"
> git_br_name =Facter.value("ks_git_#{g_repo}")
> -%>
> GIT_BRANCH  :: <%=git_branch %>
> GIT_BRANCH_NAME :: <%=git_br_name %>
> <%-
> end
> -%>
> |
> 
> and I don't get anything returned by `git_br_name` at all. If I use the
> same code in irb console, it works just fine:
> 
> |
>  irb(main):012:0>require'facter'
>  =>true
>  irb(main):013:0>git_repos =['puppet-hiera','puppet-master']
>  =>["puppet-hiera","puppet-master"]
>  irb(main):014:0>git_repos.each do|g_repo|
>  irb(main):015:1*p Facter.value("ks_git_#{g_repo}")
>  irb(main):016:1>end
>  "master"
>  "develop"
>  =>["puppet-hiera","puppet-master"]
> |
> 
> 
> What am I doing wrong in the template? if I use some other built-in
> facts instead, e.g. `Facter.value(:hostname)` - it works just okay. Does
> mean the external facts cannot be used in template? Thanks in advance.
> 
> Best,
> Santanu
> 
> -- 

Hi Sans,

I think your ERB syntax may be off. Here's an example doing something
similar. Instead of Facter.value() just put an @ in front of the fact name.

<% @nameservers.each do |nameserver| -%>
nameserver <%= nameserver %>
<% end -%>

Best regards,
-g

-- 
Garrett Honeycutt
@learnpuppet
Puppet Training with LearnPuppet.com
Mobile: +1.206.414.8658

-- 
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/b82abd3d-f322-f243-50be-3ca98b593afa%40garretthoneycutt.com.
For more options, visit https://groups.google.com/d/optout.


[Puppet Users] how to use external facts in a template?

2017-01-25 Thread Sans
Dear all,
I'm having this issue and running out of ideas. 
I have this two external facts (defined in 
/etc/facter/facts.d/extn_git_facts.txt):


root@p19-d-pmaster-001:~# facter|grep ks_git
ks_git_puppet-hiera => master 
ks_git_puppet-master => develop

I want to use these two facts in a template. Here is my pseudo code:

<%-
git_repos = ['puppet-hiera', 'puppet-master']
git_repos.each do |g_repo|
git_branch = "ks_git_#{g_repo}"
git_br_name = Facter.value("ks_git_#{g_repo}")
-%>
GIT_BRANCH  :: <%= git_branch %>
GIT_BRANCH_NAME :: <%= git_br_name %>
<%-
end
-%>

and I don't get anything returned by `git_br_name` at all. If I use the 
same code in irb console, it works just fine:

 irb(main):012:0> require 'facter'
 => true
 irb(main):013:0> git_repos = ['puppet-hiera', 'puppet-master']
 => ["puppet-hiera", "puppet-master"]
 irb(main):014:0> git_repos.each do |g_repo|
 irb(main):015:1* p Facter.value("ks_git_#{g_repo}")
 irb(main):016:1> end
 "master"
 "develop"
 => ["puppet-hiera", "puppet-master"]


What am I doing wrong in the template? if I use some other built-in facts 
instead, e.g. `Facter.value(:hostname)` - it works just okay. Does mean the 
external facts cannot be used in template? Thanks in advance.

Best,
Santanu

-- 
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/cba5d7f3-e9f8-4077-ae9f-b34ea5d0d41a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.