ansibleyamlpercy

Declare and use variable in YAML (Percy.io)


Hi I have a YAML file that looks like this -

- name: Name 1
  url: http://localhost:8080/page1
- name: Name 2
  url: http://localhost:8080/page2
- name: Name 3
  url: http://localhost:8080/page3

As you can see that http://localhost:8080/ is a common section of the url property. Is there a way to declare a variable like hostname and reuse it across the file?

I went through this doc and tried the following but it doesnt work -

- hostname: "{{http://localhost:8080}}"
- name: Name 1
  url: {{hostname}}/page1
- name: Name 2
  url: {{hostname}}/page2
- name: Name 3
  url: {{hostname}}/page3

But this doesnt work. Help!


Solution

  • I wanted to toss this suggestion in, you it looks like you're doing this for the base URL of the site you're snapshotting. You can pass a --base-url flag to the snapshot command:

    $ npx percy snapshot --base-url http://localhost:8080 snapshots.yml
    

    snapshots.yml could be:

    - name: Name 1
      url: /page1
    - name: Name 2
      url: /page2
    - name: Name 3
      url: /page3
    
    ## or
    
    - url: /page1
    - url: /page2
    - url: /page3
    

    Relevant Percy CLI PR