Skip to content

Grains file does not honor --config-dir #45315

Closed

Description

@lorengordon

Description of Issue/Question

When using the --config-dir option, grains are not read from or written to {config-dir}/grains.

Setup

Create a config dir:

mkdir C:\Foo

Also create a grains file in the config-dir with the bar grain:

PS C:\Users\Administrator> cat C:\Foo\grains
bar: bar

Steps to Reproduce Issue

PS C:\Users\Administrator> C:\salt\salt-call.bat --local --config-dir C:\Foo grains.setval foo foo
local:
    ----------
    foo:
        foo
PS C:\Users\Administrator> cat C:\salt\conf\grains
foo: foo
PS C:\Users\Administrator> C:\salt\salt-call.bat --local --config-dir C:\Foo grains.get foo
local:
    foo
PS C:\Users\Administrator> C:\salt\salt-call.bat --local --config-dir C:\Foo grains.get bar
local:

Note how the grain foo is written to the default config-dir, C:\salt\conf\grains, rather than the custom config-dir location, C:\Foo\grains.

Also note that the bar grain is not read.

Versions Report

This is Windows, obviously, but I saw the same behavior on Linux (Centos6 and 7).

PS C:\Users\Administrator> C:\salt\salt-call.bat --versions
Salt Version:
           Salt: 2016.11.6

Dependency Versions:
           cffi: 1.10.0
       cherrypy: 7.1.0
       dateutil: 2.5.3
      docker-py: Not Installed
          gitdb: 0.6.4
      gitpython: 2.0.8
          ioflo: 1.5.5
         Jinja2: 2.9.4
        libgit2: Not Installed
        libnacl: 1.4.5
       M2Crypto: Not Installed
           Mako: 1.0.4
   msgpack-pure: Not Installed
 msgpack-python: 0.4.8
   mysql-python: Not Installed
      pycparser: 2.17
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)]
   python-gnupg: 0.3.8
         PyYAML: 3.11
          PyZMQ: 16.0.1
           RAET: Not Installed
          smmap: 0.9.0
        timelib: 0.2.4
        Tornado: 4.4.1
            ZMQ: 4.1.6

System Versions:
           dist:
        machine: AMD64
        release: 2016Server
         system: Windows
        version: 2016Server 10.0.14393  Multiprocessor Free

Activity

  1. gtmanfred commented on Jan 8, 2018

    @gtmanfred
    Contributor

    screen shot 2018-01-08 at 9 12 00 am

    I am unable to replicate this, it seems to be working fine for me with 2016.11.8 on windows 2016

    Can you try upgrading to 2016.11.8 which is the latest version of 2016.11?

    Thanks,
    Daniel

  2. added
    cannot-reproduce
    needs-more-info
    on Jan 8, 2018
  3. added this to the Blocked milestone on Jan 8, 2018
  4. lorengordon commented on Jan 8, 2018

    @lorengordon
    ContributorAuthor

    @gtmanfred Try doing it without creating the minion file first.

  5. added
    bug
    severity-medium
    P4
    and removed
    cannot-reproduce
    needs-more-info
    on Jan 8, 2018
  6. modified the milestones: Blocked, Approved on Jan 8, 2018
  7. gtmanfred commented on Jan 8, 2018

    @gtmanfred
    Contributor

    Ok, i am able to replicate it if the minion file does not exist in the config directory. My guess is that there is something in there on windows that validates the config-dir path, that just reverts back to c:\salt\conf if the minion config file does not exist.

    @twangboy can you take a look at this?

    Thanks,
    Daniel

  8. 9 remaining items

  9. gtmanfred commented on Jan 8, 2018

    @gtmanfred
    Contributor

    What it seems like is happening, is if the conf_file does not exist in what the conf_dir is set to, we just keep the default, for conf_file and conf_dir, which is causing grains.setval to not write the grains to the correct file.

  10. gtmanfred commented on Jan 8, 2018

    @gtmanfred
    Contributor
        if salt.utils.validate.path.is_readable(path):
            try:
                opts = _read_conf_file(path)
                opts['conf_file'] = path
            except salt.exceptions.SaltConfigurationError as error:
                log.error(error)
                if exit_on_config_errors:
                    sys.exit(salt.defaults.exitcodes.EX_GENERIC)
        else:
            log.debug('Missing configuration file: {0}'.format(path))
    

    yup.

    https://github.com/saltstack/salt/blob/2017.7/salt/config/__init__.py#L2044-L2053

  11. gtmanfred commented on Jan 8, 2018

    @gtmanfred
    Contributor

    Thanks @lorengordon this should be fixed by #45330

    Daniel

  12. lorengordon commented on Jan 8, 2018

    @lorengordon
    ContributorAuthor

    Makes sense to me, thanks @gtmanfred! Though I think you may want to keep the original opts['conf_file'] = path in place. Otherwise, the conf_file from the file will override the cli param. (Which would admittedly be a strange way to configure and call things, but still probably isn't the correct precedence ordering).

  13. added
    fixed-pls-verify
    on Jan 8, 2018
  14. self-assigned this
    on Feb 28, 2018
  15. removed
    fixed-pls-verify
    on Jul 9, 2018
  16. gtmanfred commented on Jul 9, 2018

    @gtmanfred
    Contributor

    This is going to require a change in how we load the config file, too many tests are failing for me to feel comfortable at changing this in a minor release.

    I am going to leave this for now, if someone else runs across this, a PR would be welcome.

    Thanks,
    Daniel

  17. removed their assignment
    on Jul 9, 2018
  18. self-assigned this
    on Mar 19, 2019
  19. removed their assignment
    on Mar 30, 2019
  20. stale commented on Jan 8, 2020

    @stale

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CoreP3bugseverity-mediumstale

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions