Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module.run does not run the way described in the documentation #56422

Open
jtraub91 opened this issue Mar 20, 2020 · 12 comments
Open

Module.run does not run the way described in the documentation #56422

jtraub91 opened this issue Mar 20, 2020 · 12 comments
Labels
cannot-reproduce cannot be replicated with info/context provided
Milestone

Comments

@jtraub91
Copy link
Contributor

Description of Issue

The documentation located here describes the new and legacy style of passing arguments when using the module.run state function. However, the new style does not behave as described and the legacy style provides a warning that this will be deprecated in the Sodium release. This can be frustrating for users.

Setup

Normal salt installation. Create the following test state to demonstrate.

# test.sls

test_new_style_module_run:
  module.run:
    - test.random_hash:
      - size: 42
      - hash_type: sha256

test_legacy_style_module_run:
  module.run:
    - name: test.random_hash
    - size: 42
    - hash_type: sha256

Steps to Reproduce Issue

Run the state.

# salt \* state.apply test
ip-10-10-10-199.us-west-2.compute.internal:
----------
          ID: test_new_style_module_run
    Function: module.run
      Result: False
     Comment: Module function test_new_style_module_run is not available
     Started: 22:09:13.200256
    Duration: 1.247 ms
     Changes:
----------
          ID: test_legacy_style_module_run
    Function: module.run
        Name: test.random_hash
      Result: True
     Comment: Module function test.random_hash executed
     Started: 22:09:13.201689
    Duration: 35.354 ms
     Changes:
              ----------
              ret:
                  76a50887d8f1c2e9301755428990ad81479ee21c25b43215cf524541e0503269

Summary for ip-10-10-10-199.us-west-2.compute.internal
------------
Succeeded: 1 (changed=1)
Failed:    1
------------
Total states run:     2
Total run time:  36.601 ms
ERROR: Minions returned with non-zero exit code

Even in the successful case, the logs warn the user that this will be deprecated in Sodium.

# tail /var/log/salt/minion
2020-03-20 14:05:57,901 [salt.utils.decorators:636 ][WARNING ][12968] The function "module.run" is using its deprecated version and will expire in version "Sodium".
2020-03-20 14:05:57,901 [salt.state       :322 ][ERROR   ][12968] Module function yo is not available
2020-03-20 14:06:31,797 [salt.utils.decorators:636 ][WARNING ][13042] The function "module.run" is using its deprecated version and will expire in version "Sodium".
2020-03-20 14:06:31,798 [salt.state       :322 ][ERROR   ][13042] Module function yo is not available
2020-03-20 22:07:21,986 [salt.utils.decorators:636 ][WARNING ][9056] The function "module.run" is using its deprecated version and will expire in version "Sodium".
2020-03-20 22:07:21,988 [salt.state       :322 ][ERROR   ][9056] Module function test_new_style_module_run is not available
2020-03-20 22:08:41,383 [salt.state       :3607][CRITICAL][9130] Rendering SLS 'base:test' failed: mapping values are not allowed in this context
2020-03-20 22:09:13,201 [salt.utils.decorators:636 ][WARNING ][9146] The function "module.run" is using its deprecated version and will expire in version "Sodium".
2020-03-20 22:09:13,201 [salt.state       :322 ][ERROR   ][9146] Module function test_new_style_module_run is not available
2020-03-20 22:09:13,202 [salt.utils.decorators:636 ][WARNING ][9146] The function "module.run" is using its deprecated version and will expire in version "Sodium".

Versions Report

# salt --versions-report
Salt Version:
           Salt: 3000

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: Not Installed
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
         Jinja2: 2.8.1
        libgit2: Not Installed
       M2Crypto: 0.33.0
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.6.2
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 3.6.8 (default, Aug  7 2019, 17:28:10)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.3.0
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.1.4

System Versions:
           dist: centos 7.7.1908 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-1062.12.1.el7.x86_64
         system: Linux
        version: CentOS Linux 7.7.1908 Core
@frogunder
Copy link
Contributor

@jtraub91 Thank you for reporting this issue.

I am not able to replicate it, it seems to work correctly for me
Do you have in your minion config file:

use_superseded:
  - module.run
[root@frode1 ~]# salt \* state.apply test
frode1:
----------
          ID: test_new_style_module_run
    Function: module.run
      Result: True
     Comment: test.random_hash: c6f3ac57944a531490cd39902d0f777715fd005efac9a30622d5f5205e7f6894
     Started: 22:46:59.257568
    Duration: 62.085 ms
     Changes:   
              ----------
              test.random_hash:
                  c6f3ac57944a531490cd39902d0f777715fd005efac9a30622d5f5205e7f6894
----------
          ID: test_legacy_style_module_run
    Function: module.run
        Name: test.random_hash
      Result: True
     Comment: 
     Started: 22:46:59.319967
    Duration: 0.681 ms
     Changes:   

Summary for frode1
------------
Succeeded: 2 (changed=1)
Failed:    0
------------
Total states run:     2
Total run time:  62.766 ms
[root@frode1 ~]#

According to the docs https://docs.saltstack.com/en/latest/ref/states/all/salt.states.module.html
you will need to put in your minion config file:

use_superseded:
  - module.run

to use the new style.
When I removed that I did see the same error you are describing.

[root@frode1 ~]# salt \* state.apply test
frode1:
----------
          ID: test_new_style_module_run
    Function: module.run
      Result: False
     Comment: Module function test_new_style_module_run is not available
     Started: 22:47:42.964556
    Duration: 2.446 ms
     Changes:   
----------
          ID: test_legacy_style_module_run
    Function: module.run
        Name: test.random_hash
      Result: True
     Comment: Module function test.random_hash executed
     Started: 22:47:42.967266
    Duration: 59.223 ms
     Changes:   
              ----------
              ret:
                  d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35

Summary for frode1
------------
Succeeded: 1 (changed=1)
Failed:    1
------------
Total states run:     2
Total run time:  61.669 ms
ERROR: Minions returned with non-zero exit code
[root@frode1 ~]#

Thanks.

@frogunder frogunder added this to the Blocked milestone Mar 20, 2020
@frogunder frogunder added the expected-behavior intended functionality label Mar 20, 2020
@jtraub91
Copy link
Contributor Author

Oh. Definitely did not have use_superseded. What release are we currently on? I thought we past Sodium. But good to know, sorry I missed that.

For reference, the only thing in my minion config was the master

# cat /etc/salt/minion | grep "^[^#]"
master: localhost

@jtraub91
Copy link
Contributor Author

Also, I want to point out, in your example, and duplicated on my system with the new config, the new and legacy styles do not behave the same. What explains that discrepancy?

@hbokh
Copy link

hbokh commented Sep 24, 2020

@frogunder Is the new module.run really working as documented?
I ask because in 3001.1 and the mentioned use_superseded set in the minion config, this example from the official docs does work:

# New Style
test.random_hash:
  module.run:
    - test.random_hash:
      - size: 42
      - hash_type: sha256

but this does not:

Generate a random hash:
  module.run:
    - test.random_hash:
      - size: 42
      - hash_type: sha256

Errors with

                 ID: Generate a random hash
           Function: module.run
             Result: False
            Comment: Module function Generate a random hash is not available

I'm trying to convert a module.run for gpg.import_key, but since that keeps on failing, I made a fall back onto some of the most basic examples, which also fails...

@sagetherage sagetherage added Bug broken, incorrect, or confusing behavior needs-triage and removed expected-behavior intended functionality labels Sep 25, 2020
@sagetherage sagetherage removed this from the Blocked milestone Sep 25, 2020
@frogunder
Copy link
Contributor

@hbokh Sorry for the late reply. It seems to work correctly for me with the two state files you used.

root@ip-10-27-59-234:~# cat /etc/salt/minion | grep "^[^#]"
master: localhost
id: test
use_superseded:
  - module.run
root@ip-10-27-59-234:~# cat /srv/salt/test1.sls 
# New Style
test.random_hash:
  module.run:
    - test.random_hash:
      - size: 42
      - hash_type: sha256
root@ip-10-27-59-234:~# salt \* state.sls test1
test:
----------
          ID: test.random_hash
    Function: module.run
      Result: True
     Comment: test.random_hash: 670671cd97404156226e507973f2ab8330d3022ca96e0c93bdbdb320c41adcaf
     Started: 14:49:55.173928
    Duration: 2.226 ms
     Changes:   
              ----------
              test.random_hash:
                  670671cd97404156226e507973f2ab8330d3022ca96e0c93bdbdb320c41adcaf

Summary for test
------------
Succeeded: 1 (changed=1)
Failed:    0
------------
Total states run:     1
Total run time:   2.226 ms
root@ip-10-27-59-234:~# cat /srv/salt/test2.sls 
Generate a random hash:
  module.run:
    - test.random_hash:
      - size: 42
      - hash_type: sha256
root@ip-10-27-59-234:~# 
root@ip-10-27-59-234:~# salt \* state.sls test2
test:
----------
          ID: Generate a random hash
    Function: module.run
      Result: True
     Comment: test.random_hash: 3fdba35f04dc8c462986c992bcf875546257113072a909c162f7e470e581e278
     Started: 14:49:58.115289
    Duration: 3.364 ms
     Changes:   
              ----------
              test.random_hash:
                  3fdba35f04dc8c462986c992bcf875546257113072a909c162f7e470e581e278

Summary for test
------------
Succeeded: 1 (changed=1)
Failed:    0
------------
Total states run:     1
Total run time:   3.364 ms

What distro do you see this error on? I used Ubuntu 20 with salt 3001.1 installed.

Thanks.

@hbokh
Copy link

hbokh commented Oct 3, 2020

What distro do you see this error on? I used Ubuntu 20 with salt 3001.1 installed.

On Debian 9 "Stretch" and Salt 3001.1

@frogunder
Copy link
Contributor

I just tried on Debian 9 with Salt 3001.1 and it seems to work correctly for me.

root@ip-10-27-59-63:~# salt \* grains.item lsb_distrib_description
test:
    ----------
    lsb_distrib_description:
        Debian GNU/Linux 9.2 (stretch)
root@ip-10-27-59-63:~# salt \* grains.item saltversion
test:
    ----------
    saltversion:
        3001.1
root@ip-10-27-59-63:~# 

I do not see the error you are describing, so not sure what is causing your issue.

@frogunder frogunder added cannot-reproduce cannot be replicated with info/context provided and removed needs-triage labels Oct 7, 2020
@frogunder frogunder added this to the Blocked milestone Oct 7, 2020
@sagetherage
Copy link
Contributor

@jtraub91 is this still an issue for you?

@sagetherage sagetherage removed the Bug broken, incorrect, or confusing behavior label Jun 16, 2021
@sagetherage
Copy link
Contributor

@jtraub91 is this still an issue and needs either a code fix and/or doc fix?

@Exagone313
Copy link

I have the same issue with Salt 3002.7 on Debian stretch:

hello world:
  module.run:
    - cmd.run:
      - cmd: "echo hello world"
sudo salt my-minion state.apply foo
my-minion:
----------
          ID: hello world
    Function: module.run
      Result: False
     Comment: Module function hello world is not available
     Started: 12:36:39.533395
    Duration: 2.836 ms
     Changes:

However this state works:

hello world:
  module.run:
    - name: cmd.run
    - cmd: "echo hello world"

@emnavarro02
Copy link

I have this problem too, running salt 3005.1

@emnavarro02
Copy link

Never mind, I figured out my minions are running version 3004.3, and they were missing the parameter in the minion config file:

use_superseded:
  - module.run

After adding this parameter to the config file, the so-called modern approach works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cannot-reproduce cannot be replicated with info/context provided
Projects
None yet
Development

No branches or pull requests

6 participants