Jira (PUP-8500) puppet lookup cli should support adding facts as arguments, not just from a file.

0 views
Skip to first unread message

Just (JIRA)

unread,
Feb 28, 2018, 1:11:02 PM2/28/18
to puppe...@googlegroups.com
Just created an issue
 
Puppet / New Feature PUP-8500
puppet lookup cli should support adding facts as arguments, not just from a file.
Issue Type: New Feature New Feature
Affects Versions: PUP 5.4.0
Assignee: Unassigned
Attachments: lookup_direct_fact_option.patch
Created: 2018/02/28 10:10 AM
Priority: Normal Normal
Reporter: Just

Puppet Version: 5.4.0
Puppet Server Version: n/a
OS Name/Version: Ubuntu 16.04

It would be very useful if "puppet lookup allowed specify facts as direct arguments a parameter.

When automating something that uses "puppet lookup", having to write a temporary file containing some facts, then deleting the file afterwards is a pain, and is potentially fragile.

If the facts could be specified directly, there would be no need for the file.

Desired Behavior:

/opt/puppetlabs/bin/puppet lookup site_domain --environment boo --facts test_facts.yaml --node myhost.r00.zone1.foo.bar.com --node_terminus=plain --external_nodes=none --fact boo=test --fact test=boo --fact asdfasd=123
~~~8<~~~
$ echo $?
0

Actual Behavior:

/opt/puppetlabs/bin/puppet lookup site_domain --environment boo --facts test_facts.yaml --node myhost.r00.zone1.foo.bar.com --node_terminus=plain --external_nodes=none --fact boo=test --fact test=boo --fact asdfasd=123
Error: Could not parse application options: invalid option: --fact
$ echo $?
130

 

I've attached a patch which basically works, but I'm not very familiar with the code base, and so there's probably some style and other functional things I'm not considering.

I'd be happy to create a PR, but let's see the patch is even close first

Thanks.

 

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.5.1#75006-sha1:7df2574)
Atlassian logo

Just (JIRA)

unread,
Feb 28, 2018, 1:32:04 PM2/28/18
to puppe...@googlegroups.com
Just updated an issue
Change By: Just
*Puppet Version: 5.4.0*
*Puppet Server Version: n/a*
*OS Name/Version: Ubuntu 16.04*


It would be very useful if "puppet lookup
" allowed specify facts as direct arguments a parameter.


When automating something that uses "puppet lookup", having to write a temporary file containing some facts, then deleting the file afterwards is a pain, and is potentially fragile.

If the facts could be specified directly, there would be no need for the file.

*Desired Behavior:*
{code:java}

/opt/puppetlabs/bin/puppet lookup site_domain --environment boo --facts test_facts.yaml --node myhost.r00.zone1.foo.bar.com --node_terminus=plain --external_nodes=none --fact boo=test --fact test=boo --fact asdfasd=123
~~~8<~~~
$ echo $?
0{code}
*Actual Behavior:*
{code:java}

/opt/puppetlabs/bin/puppet lookup site_domain --environment boo --facts test_facts.yaml --node myhost.r00.zone1.foo.bar.com --node_terminus=plain --external_nodes=none --fact boo=test --fact test=boo --fact asdfasd=123
Error: Could not parse application options: invalid option: --fact
$ echo $?
130
{code}

 

I've attached a patch which basically works, but I'm not very familiar with the code base, and so there's probably some style and other functional things I'm not considering.

I'd be happy to create a PR, but let's see the patch is even close first :)

Thanks.

 

Just (JIRA)

unread,
Feb 28, 2018, 1:33:01 PM2/28/18
to puppe...@googlegroups.com
Just updated an issue
*Puppet Version: 5.4.0*
*Puppet Server Version: n/a*
*OS Name/Version: Ubuntu 16.04*

It would be very useful if "puppet lookup" allowed specify facts setting fact overrides as direct arguments a parameter.


When automating something that uses "puppet lookup", having to write a temporary file containing some facts, then deleting the file afterwards is a pain, and is potentially fragile.

If the facts could be specified directly, there would be no need for the file.

*Desired Behavior:*
{code:java}/opt/puppetlabs/bin/puppet lookup site_domain --environment boo --facts test_facts.yaml --node myhost.r00.zone1.foo.bar.com --node_terminus=plain --external_nodes=none --fact boo=test --fact test=boo --fact asdfasd=123
~~~8<~~~
$ echo $?
0{code}
*Actual Behavior:*
{code:java}/opt/puppetlabs/bin/puppet lookup site_domain --environment boo --facts test_facts.yaml --node myhost.r00.zone1.foo.bar.com --node_terminus=plain --external_nodes=none --fact boo=test --fact test=boo --fact asdfasd=123
Error: Could not parse application options: invalid option: --fact
$ echo $?
130
{code}
 

I've attached a patch which basically works, but I'm not very familiar with the code base, and so there's probably some style and other functional things I'm not considering.

I'd be happy to create a PR, but let's see the patch is even close first :)

Thanks.

 

Just (JIRA)

unread,
Feb 28, 2018, 1:34:02 PM2/28/18
to puppe...@googlegroups.com
Just updated an issue
*Puppet Version: 5.4.0*
*Puppet Server Version: n/a*
*OS Name/Version: Ubuntu 16.04*

It would be very useful if "puppet lookup" allowed setting fact overrides as direct arguments to a parameter.


When automating something that uses "puppet lookup", having to write a temporary file containing some facts, then deleting the file afterwards is a pain, and is potentially fragile.

If the facts could be specified directly, there would be no need for the file.

*Desired Behavior:*
{code:java}/opt/puppetlabs/bin/puppet lookup site_domain --environment boo --facts test_facts.yaml --node myhost.r00.zone1.foo.bar.com --node_terminus=plain --external_nodes=none --fact boo=test --fact test=boo --fact asdfasd=123
~~~8<~~~
$ echo $?
0{code}
*Actual Behavior:*
{code:java}/opt/puppetlabs/bin/puppet lookup site_domain --environment boo --facts test_facts.yaml --node myhost.r00.zone1.foo.bar.com --node_terminus=plain --external_nodes=none --fact boo=test --fact test=boo --fact asdfasd=123
Error: Could not parse application options: invalid option: --fact
$ echo $?
130
{code}
 

I've attached a patch which basically works, but I'm not very familiar with the code base, and so there's probably some style and other functional things I'm not considering.

I'd be happy to create a PR, but let's see the patch is even close first :)

Thanks.

 

Craig Gomes (JIRA)

unread,
Mar 5, 2018, 5:28:02 PM3/5/18
to puppe...@googlegroups.com
Craig Gomes updated an issue
Change By: Craig Gomes
Sub-team: Coremunity Language
This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo

Craig Gomes (JIRA)

unread,
Mar 5, 2018, 5:29:03 PM3/5/18
to puppe...@googlegroups.com

Henrik Lindberg (JIRA)

unread,
Mar 9, 2018, 9:37:02 PM3/9/18
to puppe...@googlegroups.com

Thomas Hallgren (JIRA)

unread,
Mar 10, 2018, 4:16:03 AM3/10/18
to puppe...@googlegroups.com
Thomas Hallgren commented on New Feature PUP-8500
 
Re: puppet lookup cli should support adding facts as arguments, not just from a file.

An idea, wouldn't it be simpler if we allowed the facts to be read from stdin by using a dash as the name of the facts file? Your command would be similar to:

{code:java}/opt/puppetlabs/bin/puppet lookup site_domain --environment boo --facts - --node myhost.r00.zone1.foo.bar.com --node_terminus=plain --external_nodes=none <<END
boo: test
test: boo
asdfasd: 123
END

Pros:

  • No need to repeat an option
  • Full YAML syntax available (arrays, hashes, etc.)
  • Very minor adjustments needed in existing code.
  • Can read facts using a pipe.

Cons:

  • Added EOF tags.

Henrik Lindberg (JIRA)

unread,
Mar 10, 2018, 4:33:02 AM3/10/18
to puppe...@googlegroups.com

What if you want to use facts file and override one or a couple of facts?
I can imagine that one of the typical facts files available for testing purposes (or one you obtained from an actual node) is used and you want to try out some custom additions.

Thomas Hallgren (JIRA)

unread,
Mar 10, 2018, 6:21:02 AM3/10/18
to puppe...@googlegroups.com

That can be achieved by allowing more than one --facts option and then process each file in order and merge their content so that last one wins. Overrides can then be added from the command-line by letting the argument to the last one be a dash.

Henrik Lindberg (JIRA)

unread,
Mar 11, 2018, 2:49:02 PM3/11/18
to puppe...@googlegroups.com

Just (JIRA)

unread,
Mar 12, 2018, 4:29:02 AM3/12/18
to puppe...@googlegroups.com
Just commented on New Feature PUP-8500

Yeah - stdin sounds fine to me.

It does what I need, and is actually more flexible as well.

Good stuff.

Henrik Lindberg (JIRA)

unread,
Mar 12, 2018, 4:44:02 AM3/12/18
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
 
Change By: Henrik Lindberg
*Puppet Version: 5 It would be very useful if "puppet lookup" allowed setting fact overrides as direct arguments to a parameter . 4

When automating something that uses "puppet lookup", having to write a temporary file containing some facts, then deleting the file afterwards is a pain, and is potentially fragile
. 0*
*Puppet Server Version: n/
If the facts could be specified directly, there would be no need for the file.

After some discussion - [~thomas.hallgren]'s idea of using {{\--facts}} with a dash to indicate "read from stdin" and that {{\--facts}} can be given multiple times on the command line to indicate in the order keys override each other. For example starting with a canned standard facts file overriding with input from stdin.

Special cases:
* if EOF is immediately read on stdin this is taken as an empty set of facts (rather than a YAML read error)
*
OS Name/Version: Ubuntu 16 consider allowing dotted keys to only modify a nested fact value (you would otherwise have to specify full structure) - this could be added in a separate ticket . 04*

Original
------
It would be very useful if "puppet lookup" allowed setting fact overrides as direct arguments to a parameter.

When automating something that uses "puppet lookup", having to write a temporary file containing some facts, then deleting the file afterwards is a pain, and is potentially fragile.

If the facts could be specified directly, there would be no need for the file.

*Desired Behavior:*
{code:java}/opt/puppetlabs/bin/puppet lookup site_domain --environment boo --facts test_facts.yaml --node myhost.r00.zone1.foo.bar.com --node_terminus=plain --external_nodes=none --fact boo=test --fact test=boo --fact asdfasd=123
~~~8<~~~
$ echo $?
0{code}
*Actual Behavior:*
{code:java}/opt/puppetlabs/bin/puppet lookup site_domain --environment boo --facts test_facts.yaml --node myhost.r00.zone1.foo.bar.com --node_terminus=plain --external_nodes=none --fact boo=test --fact test=boo --fact asdfasd=123
Error: Could not parse application options: invalid option: --fact
$ echo $?
130
{code}
 

I've attached a patch which basically works, but I'm not very familiar with the code base, and so there's probably some style and other functional things I'm not considering.

I'd be happy to create a PR, but let's see the patch is even close first :)

Thanks.

 

Josh Cooper (JIRA)

unread,
Mar 16, 2018, 5:01:04 PM3/16/18
to puppe...@googlegroups.com

Henrik Lindberg (JIRA)

unread,
Mar 22, 2018, 5:28:02 AM3/22/18
to puppe...@googlegroups.com

Henrik Lindberg (JIRA)

unread,
Mar 24, 2018, 11:22:02 AM3/24/18
to puppe...@googlegroups.com
Henrik Lindberg commented on New Feature PUP-8500
 
Re: puppet lookup cli should support adding facts as arguments, not just from a file.

Thomas Hallgren If supporting dots it would be when specifying a fact on the command line - not in the facts files.

Thomas Hallgren (JIRA)

unread,
Mar 24, 2018, 11:44:02 AM3/24/18
to puppe...@googlegroups.com

I understand that and I'm not in favor of it since it calls for a new option just to cover a corner case. It might also lead to confusion since dotted keys are allowed in the facts file (they need to be quoted when looked up).

Henrik Lindberg (JIRA)

unread,
Mar 24, 2018, 3:48:03 PM3/24/18
to puppe...@googlegroups.com

Henrik Lindberg (JIRA)

unread,
Mar 24, 2018, 3:49:03 PM3/24/18
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
It would be very useful if "puppet lookup" allowed setting fact overrides as direct arguments to a parameter.

When automating something that uses "puppet lookup", having to write a temporary file containing some facts, then deleting the file afterwards is a pain, and is potentially fragile.

If the facts could be specified directly, there would be no need for the file.

After some discussion - [~thomas.hallgren]'s idea of using {{\--facts}} with a dash to indicate "read from stdin" and that {{\--facts}} can be given multiple times on the command line to indicate in the order keys override each other. For example starting with a canned standard facts file overriding with input from stdin.

Special cases:
* if EOF is immediately read on stdin this is taken as an empty set of facts (rather than a YAML read error)
* - consider allowing dotted keys to only modify a nested fact value (you would otherwise have to specify full structure) - this could be added in a separate ticket. -

Original
------
It would be very useful if "puppet lookup" allowed setting fact overrides as direct arguments to a parameter.

When automating something that uses "puppet lookup", having to write a temporary file containing some facts, then deleting the file afterwards is a pain, and is potentially fragile.

If the facts could be specified directly, there would be no need for the file.

*Desired Behavior:*
{code:java}/opt/puppetlabs/bin/puppet lookup site_domain --environment boo --facts test_facts.yaml --node myhost.r00.zone1.foo.bar.com --node_terminus=plain --external_nodes=none --fact boo=test --fact test=boo --fact asdfasd=123
~~~8<~~~
$ echo $?
0{code}
*Actual Behavior:*
{code:java}/opt/puppetlabs/bin/puppet lookup site_domain --environment boo --facts test_facts.yaml --node myhost.r00.zone1.foo.bar.com --node_terminus=plain --external_nodes=none --fact boo=test --fact test=boo --fact asdfasd=123
Error: Could not parse application options: invalid option: --fact
$ echo $?
130
{code}
 

I've attached a patch which basically works, but I'm not very familiar with the code base, and so there's probably some style and other functional things I'm not considering.

I'd be happy to create a PR, but let's see the patch is even close first :)

Thanks.

 

Darragh (JIRA)

unread,
Oct 24, 2018, 11:59:03 AM10/24/18
to puppe...@googlegroups.com
Darragh commented on New Feature PUP-8500
 
Re: puppet lookup cli should support adding facts as arguments, not just from a file.

Just wanted to add for those searching for some way to set a simple fact temporarily during lookup you can use an env variable called 'FACTER_<name>=<value>'. This seems like it'd only work for simple facts, but for others search for a way to avoid a temporary file for simple facts figured this is a useful note to have in this Jira.

David McTavish (Jira)

unread,
Dec 6, 2021, 2:40:01 PM12/6/21
to puppe...@googlegroups.com
David McTavish updated an issue
 
Change By: David McTavish
Labels: final_triage
This message was sent by Atlassian Jira (v8.13.2#813002-sha1:c495a97)
Atlassian logo

David McTavish (Jira)

unread,
Dec 6, 2021, 2:40:03 PM12/6/21
to puppe...@googlegroups.com

Josh Cooper (Jira)

unread,
Jan 13, 2022, 1:32:02 AM1/13/22
to puppe...@googlegroups.com
Josh Cooper commented on New Feature PUP-8500
 
Re: puppet lookup cli should support adding facts as arguments, not just from a file.

We don't have plans on adding this, but if someone wanted to submit a PR here's what would need to happen:

1. Update the description to mention stdin: https://github.com/puppetlabs/puppet/blob/9b4e3473fb3fe439aef1c6875d7520c5a2d74058/lib/puppet/application/lookup.rb#L180-L183

2. Check for dash when reading the option:

https://github.com/puppetlabs/puppet/blob/main/lib/puppet/application/lookup.rb#L351-L361

We do something similar in https://github.com/puppetlabs/puppet/blob/9b4e3473fb3fe439aef1c6875d7520c5a2d74058/lib/puppet/application/apply.rb#L393 if you do puppet apply without a file or "-e"

3. Add a test in spec/unit/application/lookup_spec.rb

That said, we don't have plans on implementing this, so I'm going to close. Please reopen if you'd like to submit a PR.

This message was sent by Atlassian Jira (v8.20.2#820002-sha1:829506d)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages