Salt: Trigger a custom State into a Warning

Created on 15 Apr 2019  路  3Comments  路  Source: saltstack/salt

Question

Hi everyone,

  • Is there a way to trigger a custom state as a warning instead of Succeeded/Failed ?

Setup

For example i have this custom state in a sls :

{{ state_id }}_{{ virtual_host }}_{{ loop.index }}_configr:
  test_apache.manage:
    - name: {{ apache_root }}/{{ apache_environnement.dir_confD }}/{{ virtual_host|replace("/","_") }}/{{ pathname }}/conf_header_location.conf
    - user: {{ username }}
    - group: root
    - mode: 644
    - template: jinja

And i want to trigger it as warning instead of Succeeded/Failed like :

Summary for local
--------------
Succeeded: 149 (changed=36)
Failed:      0
Warnings:   1

I tried to put some log.warning in my python code, or to use the salt deprecation code (salt.utils.warn_until) but the state still succeed, and no warnings is raised.
I've looked up in the salt documentation/code without any luck.

Versions Report

Salt Version:
           Salt: 2017.7.8

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: Not Installed
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: 0.28.2
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.5 (default, Oct 30 2018, 23:45:53)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.3.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: centos 7.6.1810 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-957.1.3.el7.x86_64
         system: Linux
        version: CentOS Linux 7.6.1810 Core

Question info-needed stale

Most helpful comment

Hello,

Late answer but i finally found how to do it.
You can pass the warning in the return of the custom state :
ret = {'name': name, 'changes': {}, 'result': 'True', 'comment': '', 'warnings': '' }

After that you can formate and return the warning

   warning = ["this state is deprecated"]
   ret['warnings'] =  warning

And it'll look like this :

      Result: Warning
     Comment: Warning
     Started: 08:34:42.699374
    Duration: 1.767 ms
     Changes:
    Warnings: This state is deprecated
Succeeded: 138 (changed=35)
Failed:      0
Warnings:    3

All 3 comments

@Arguros sorry, probably I'm wrong, but I see no Warnings: line at all in salt output and I see no any mention of Warnings: in salt source code. Are you talking about a new feature proposal? If so could you please follow the https://github.com/saltstack/salt-enhancement-proposals ?

Hello,

Late answer but i finally found how to do it.
You can pass the warning in the return of the custom state :
ret = {'name': name, 'changes': {}, 'result': 'True', 'comment': '', 'warnings': '' }

After that you can formate and return the warning

   warning = ["this state is deprecated"]
   ret['warnings'] =  warning

And it'll look like this :

      Result: Warning
     Comment: Warning
     Started: 08:34:42.699374
    Duration: 1.767 ms
     Changes:
    Warnings: This state is deprecated
Succeeded: 138 (changed=35)
Failed:      0
Warnings:    3

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

allyunion picture allyunion  路  3Comments

saurabhnemade picture saurabhnemade  路  3Comments

qiushics picture qiushics  路  3Comments

Oloremo picture Oloremo  路  3Comments

sfozz picture sfozz  路  3Comments