Can you use facts in a YAML based Bolt plan?

306 Views Asked by At

The Bolt docs on Writing plans in YAML gives an code snippet that is not supposed to work:

steps:
  - targets: $targets
    description: Apply a file resource
    resources:
    - type: file
      title: '/tmp/foo'
      parameters:
        content: $facts['os']['family']
        ensure: present
  - name: file_contents
    description: Read contents of file managed with file resource
    eval: >
      file::read('/tmp/foo')
      
return: $file_contents

This snippet could be vastly improved with a GIANT RED "THIS DOES NOT WORK" right next to it.

I want to do exactly that: use a values from facts in a step. I understand I could use the puppet language to do so, but I'd like to use YAML.

EDIT: How can you write the above in YAML?

1

There are 1 best solutions below

4
On

I would use the facts function instead to be safe, and functions are possible in YAML plans.

${facts(<target>)['os']['family']}

Since the step in the question already supplies a target type, it does not need to be converted from a TargetSpec type with get_target like in Puppet language plans.

Note that you may need to gather the facts with another plan before referencing them:

steps:
- plan: facts
  description: 'Gather facts for the servers using the built-in facts plan'
  parameters:
    targets:
    - foo.example.com
    - bar.example.com
    - baz.example.com