0

I want to run a command (cmd.run) which uses files within the salt directory, for example:

fly_set_{{ pipeline }}:
  cmd.run:
    - name: |
        fly -t ci set-pipeline -p {{ pipeline }} -c pipeline.yml -l credentials.yml
    - require:
      - cmd: fly_login_{{name}}
        - file: /etc/concourse/teams/builds/{{ pipeline }}/pipeline.yml
        - file: /etc/concourse/teams/builds/{{ pipeline }}/credentials.yml

Is this the correct approach or do I need to do this first?

file:
  managed:
    - source: salt://concourse/teams/builds/{{ pipeline }}/pipeline.yml
Josh Correia
  • 3,807
  • 3
  • 33
  • 50
blane
  • 9
  • 6

1 Answers1

3

I'm not sure exactly what are you trying to achieve, but if your command is depending on multiple files the right way to do this would be:

/etc/concourse/teams/builds/{{ pipeline }}/pipeline.yml:
  file.managed:
    - source: salt://concourse/teams/builds/{{ pipeline }}/pipeline.yml

/etc/concourse/teams/builds/{{ pipeline }}/credentials.yml:
  file.managed:
    - source: salt://concourse/teams/builds/{{ pipeline }}/credentials.yml

fly_set_{{ pipeline }}:
  cmd.run:
    - name: |
        fly -t ci set-pipeline -p {{ pipeline }} -c pipeline.yml -l credentials.yml
    - require:
      - file: /etc/concourse/teams/builds/{{ pipeline }}/pipeline.yml
      - file: /etc/concourse/teams/builds/{{ pipeline }}/credentials.yml

First two file.managed directive will ensure that both files are present on the minion. The require directive in cmd.run will make sure that files are present on the minion before the execution of the command.

alexK
  • 963
  • 1
  • 7
  • 17