Skip to content

Commit f3490c2

Browse files
committed
Add section on indexing facts to the octofacts-updater document
1 parent 16bd93b commit f3490c2

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

doc/octofacts-updater.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,40 @@ Note that `facter` may need to run as root to gather all of the facts for the sy
9999

100100
Also, if you are using Puppet 4 or later, but are relying on "legacy" facts that were used in Puppet 3, you may need to add `--show-legacy` to the `facter` command line.
101101

102+
## Indexing facts
103+
104+
`octofacts` supports an index of facts, allowing you to select fixtures dynamically based on parameters, rather than by specifying the name of a specific file in your tests. When properly set up, the use of an index in rspec-puppet tests will look like this example:
105+
106+
```
107+
let(:facts) { Octofacts.from_index(app: "my_app", role: "my_role") }
108+
```
109+
110+
To set up the index, you need to configure three settings:
111+
112+
- `file`: The absolute or relative path to the index file.
113+
- `node_path`: The absolute or relative path to the directory where fixtures for nodes are stored.
114+
- `indexed_facts`: An array of facts that you want to index. For the example above, you would need to index the `app` and `role` facts.
115+
116+
In your configuration, this might look like:
117+
118+
```title=octofacts-updater.yaml
119+
index:
120+
file: ../spec/fixtures/facts/octofacts-index.yaml
121+
node_path: ../spec/fixtures/facts/octofacts
122+
indexed_facts:
123+
- app
124+
- role
125+
```
126+
127+
Once you have configured the index, you can use `octofacts-updater` to build the index from the node fixtures you already have.
128+
129+
```
130+
touch spec/fixtures/facts/octofacts-index.yaml
131+
octofacts-updater --config octofacts-updater.yaml --action reindex
132+
```
133+
134+
:information_source: If a file or directory path starts with `.` or `..`, the path is treated as relative to the configuration file itself. This allows you to specify locations within a Puppet code repository, without regard to where on the system `octofacts-updater` is actually installed. Of course, you can also use absolute paths (starting with `/`).
135+
102136
## Anonymizing and rewriting facts
103137

104138
To avoid committing sensitive information into source control, and to prevent rspec-puppet tests from inadvertently contacting actual systems, `octofacts-updater` supports anonymizing and rewriting facts. For example, you might remove or scramble SSH keys, delete or hard-code facts like system uptime that change upon each run, or change IP addresses.

0 commit comments

Comments
 (0)