saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.16k stars 5.48k forks source link

[BUG] salt.cmd.run('df -h') throws error #61753

Closed abh23 closed 1 year ago

abh23 commented 2 years ago

Description Trying to set output of salt['cmd.run']('df -hl') to a variable like: {%- set df_check = salt['cmd.run']('df -hl') -%}

Steps to Reproduce the behavior

  1. Set variable as {%- set df_check = salt['cmd.run']('df -hl') -%}
  2. Write variable into file as:
    create_file:
    file.managed:
    - name: diskusage.txt
    - group: root
    - mode: '0600'
    - contents_newline: True
    - contents: |
        df: {{ df_check }}

Expected behavior The variable should get written into the file.

Versions Report


Salt Version:
          Salt: 3004

Dependency Versions:
          cffi: Not Installed
      cherrypy: unknown
      dateutil: Not Installed
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 2.10
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 0.5.6
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: Not Installed
      pycrypto: Not Installed
  pycryptodome: 3.6.1
        pygit2: Not Installed
        Python: 3.7.10 (default, Jun  3 2021, 00:02:01)
  python-gnupg: Not Installed
        PyYAML: 4.2
         PyZMQ: 17.0.0
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.2.3

System Versions:
          dist: amzn 2
        locale: UTF-8
       machine: x86_64
       release: 5.10.96-90.460.amzn2.x86_64
        system: Linux
       version: Amazon Linux 2

whytewolf commented 2 years ago

what error are you getting? there is a lack of information needed to figure out what is happening here. is it not getting set? are you running the cmd.run in a jinja loop? etc. more info about what is happening is needed.

OrangeDog commented 2 years ago

Almost certainly you need to fix the indentation of the jinja substitution. Using a template rather than contents would make it easier if you want the df: at the beginning.

garethgreenaway commented 1 year ago

@abh23 Making sure you saw the comments above.

abh23 commented 1 year ago

Oh I certainly did. We can close this. Thanks for the help.