Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to call parseYAML #1343

Closed
fernferret opened this issue Feb 23, 2020 · 2 comments · Fixed by #1344
Closed

Add the ability to call parseYAML #1343

fernferret opened this issue Feb 23, 2020 · 2 comments · Fixed by #1344

Comments

@fernferret
Copy link
Contributor

Consul Template version

./consul-template -v
 v0.24.1 ()

Configuration

# Copy-paste your configuration files here. Only include what is necessary or
# what you've changed from defaults. Include all referenced configurations.
N/A
<!-- Copy-paste your Consul Template template here -->
<html>
  <table>
    <tr>
      <th>Name</th>
      <th>Detail</th>
    </tr>
    {{- with $g := key "help.yaml" | parseYAML }}
    {{- range index $g.rows 0 }}
    <tr>
      <td>{{ .name }}</td>
      <td>{{ .msg }}</td>
    </tr>
    {{- end }}
    {{- end }}
  </table>
</html>
# Include sample data you reference in the template from Consul or Vault here.
rows:
- - name: Wiki
    msg: Editable knowledge base that contains a lot of helpful things.
    btn: Open The Wiki
    tags:
    - name: Wiki

  - name: Unifi Protect
    msg: Manage and view cameras via the UniFi Protect web interface.
    # default button will be "Open $TITLE"
    # btn: Open The Wiki
    tags:
    - name: Cameras
    
  - name: UniFi Management
    msg: Manage the network including Switches, Router and Access Points. Also manage/view VPN settings.
    btn: Open UniFi
    tags:
    - name: Network

Command

# Place your Consul Template command here
$ ./consul-template -consul-addr https://consul.lab -template test.html.ct -once -dry
<html>
  <table>
    <tr>
      <th>Name</th>
      <th>Detail</th>
    </tr>
    <tr>
      <td>StokesNet Wiki</td>
      <td>Editable knowledge base that contains a lot of helpful things.</td>
    </tr>
    <tr>
      <td>Unifi Protect</td>
      <td>Manage and view cameras via the UniFi Protect web interface.</td>
    </tr>
    <tr>
      <td>UniFi Management</td>
      <td>Manage the network including Switches, Router and Access Points. Also manage/view VPN settings to StokesNet UK.</td>
    </tr>
  </table>
</html>

Debug output

Provide a link to a GitHub Gist containing the complete debug
output by running with -log-level=trace.
N/A

Expected behavior

What should have happened?

YAML would be parsed just like JSON

Actual behavior

What actually happened?
parseYAML is not a valid helper so it breaks.

Steps to reproduce

See above template

Details

I did this a bit backwards, I already have the PR ready but forgot to read the contrib guide that said I needed an issue first. The issue template here seems to be provided for mainly bugs but I tried filling it out the best I could.

@thatsk
Copy link

thatsk commented Jan 7, 2021

how to access tags.name ?

@eikenb
Copy link
Contributor

eikenb commented Jan 7, 2021

Hey @thatsk, if you have a question you might want to ask on the community discussion site at https://discuss.hashicorp.com/c/consul/29. It'll get a lot more eyes on it there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants