Skip to content

Commit

Permalink
(maint) - Add README section on overwrite_fact
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbreen28 committed Jul 20, 2023
1 parent 977acc2 commit c5f5fc8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,22 @@ To do this, pass a lambda as the value for the custom fact. The lambda is passed
add_custom_fact :root_home, lambda { |os,facts| "/tmp/#{facts['hostname']}" }
```

#### Overwrite existing facts

You can also supply an optional input `:overwrite_fact` to the `add_custom_fact` method.

This allows you to completely overwrite a fact already present in the facts hash as oppose to deep merging the fact values.

```ruby
add_custom_fact :networking, { "ip" => "127.0.0.1", "ip6" => "FE80:0000:0000:0000:AAAA:AAAA:AAAA", "mac" => "AA:AA:AA:AA:AA:AA"}, :overwrite_fact => true
```

will return the following hash when queried for networking facts

```ruby
:networking => { "ip" => "127.0.0.1", "ip6" => "FE80:0000:0000:0000:AAAA:AAAA:AAAA", "mac" => "AA:AA:AA:AA:AA:AA"}
```

### Supplying Custom External Facts through FacterDB
Rspec-puppet-facts uses a gem called facterdb that contains many fact sets of various combinations that are pre generated. Rspec-puppet-facts queries
facterdb to pull out a specific fact set to use when testing.
Expand Down

0 comments on commit c5f5fc8

Please sign in to comment.