how to linting sls-files?

134 views
Skip to first unread message

stefa...@googlemail.com

unread,
Aug 17, 2021, 8:41:32 AM8/17/21
to Salt-users

Hello there,


how do you linting sls-files? so that means check if there any typoes or other things that don't work, I've 3 steps in my gitlab-ci which works more or less, but the biggest problem is the pillar thing, some states are for specific hosts so I got an error, how do you handle this?
My config look like that:
```
image:
  name: debian:buster

default:
 before_script:
    - DEBIAN_FRONTEND=noninteractive apt update -qq
    - DEBIAN_FRONTEND=noninteractive apt install -yqq python3-pip wget apt-utils gnupg
    - pip3 install yamllint
    - pip3 install salt-lint
    - mkdir -p /srv/salt
    - cp -r $CI_PROJECT_DIR/* /srv/salt

stages:
  - Lint
  - Test

linux:lint:
  stage: Lint
  needs: []
  tags:
    - docker
  script:
    - wget -O - https://repo.saltproject.io/py3/debian/10/amd64/latest/salt-archive-keyring.gpg | apt-key add -
    - "echo 'deb https://repo.saltproject.io/py3/debian/10/amd64/latest buster main' > /etc/apt/sources.list.d/salt.list"
    - DEBIAN_FRONTEND=noninteractive apt update -qq && DEBIAN_FRONTEND=noninteractive apt install salt-minion -yqq
    - "echo 'file_client: local' >> /etc/salt/minion"
    - find /srv -type f -name "*.sls" ! -path "*states/win/*" | xargs --no-run-if-empty salt-lint -x 201 -x 207 -x 208 -x 204
    - cd /srv/salt/states && for i in *; do echo $i; salt-call --id=test-minion.aei.mpg.de --local --file-root=/srv/salt/states --pillar-root=/srv/salt/pillars --retcode-passthrough state.show_sls linux.${i%.*} ; done
  only:
    - branches

highstate:
  stage: Test
  needs: ["linux:lint"]
  tags:
    - docker
  script:
    - salt-call state.highstate --local --retcode-passthrough mocked=True --state-output=mixed --state_verbose=False
  only:
    - master

```
thanks for help!
Reply all
Reply to author
Forward
0 new messages