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

[BUG] Custom grains on Windows minion doesn't work #63024

Closed
kTipSSIoYv opened this issue Nov 5, 2022 · 3 comments
Closed

[BUG] Custom grains on Windows minion doesn't work #63024

kTipSSIoYv opened this issue Nov 5, 2022 · 3 comments
Labels
Bug broken, incorrect, or confusing behavior Grains needs-triage Salt-Cloud Windows

Comments

@kTipSSIoYv
Copy link

kTipSSIoYv commented Nov 5, 2022

Description
I'm trying to configure newly provisioned azure VM's with custom grains. It works fine on Linux VM's. But for windows VM's the grains are in the server but it doesn't show when we run the command salt 'wintest-001' grains.items.

How do you define custom grains for Windows minions?

Update: There seems to two location for Grains and Minion config on Windows VM's. The Salt process is looking for configs from C:\Program Data\salt-project\. But the grains defined in profile are written in c:\salt\grains and c:\salt\minion. If I move the grains file to C:\Program Data\salt-project\grains then it works as expected.

How can I configure the profile to write grains data under C:\Program Data\salt-project\ instead of c:\salt?

Steps to Reproduce the behavior

Create a windows azure profile as shown below.

azure-win2019:
  provider: my-azure-config
  image: MicrosoftWindowsServer|WindowsServer|2019-datacenter-gensecond|latest
  size: Standard_B2ms
  location: 'westeurope'
  win_username: azureuser
  win_password: 'Verybadpass'
  use_winrm: True
  winrm_verify_ssl: False
  winrm_port: 5986
  #smb_port: 445
  allocate_public_ip: True
  security_group: saltstack-nsg
  win_installer: /srv/salt/win/files/Salt-Minion-3004.2-1-Py3-AMD64-Setup.exe
  userdata_file: https://raw.githubusercontent.com/xxxxx/Windows-firewall.ps1
  grains:
    environment: production
  sync_after_install: grains

Deploy a new VM using the following command.

salt-cloud -p azure-win2019 wintest-001

After the provision is complete, check the grains and the environment grain is missing.

root@salt:/etc/salt/cloud.profiles.d# salt 'wintest-001' grains.items | grep production
No matches

If you RDP to the new VM, you can see that grains file exists in the VM.

image

Here is the content of the minion config:

hash_type: sha256
id: wintest-001
ipc_mode: tcp
log_level: info
master: 10.10.10.10
master_finger: 7f:49:b4:86:11:27:7b:30:76:85:2c:2
multiprocessing: false
pki_dir: /conf/pki/minion
root_dir: c:\salt

I tried restarting salt services as well. But still its not showing up.

Expected behavior
Custom grains should show up just like it does for Linux

Versions Report

salt --versions-report

root@salt:~# salt --versions-report
Salt Version:
Salt: 3005.1

Dependency Versions:
cffi: 1.15.1
cherrypy: Not Installed
dateutil: 2.8.1
docker-py: Not Installed
gitdb: 4.0.9
gitpython: 3.1.24
Jinja2: 3.0.3
libgit2: 1.1.0
M2Crypto: 0.38.0
Mako: Not Installed
msgpack: 1.0.3
msgpack-pure: Not Installed
mysql-python: Not Installed
pycparser: 2.21
pycrypto: Not Installed
pycryptodome: 3.11.0
pygit2: 1.6.1
Python: 3.10.6 (main, Nov 2 2022, 18:53:38) [GCC 11.3.0]
python-gnupg: 0.4.8
PyYAML: 5.4.1
PyZMQ: 22.3.0
smmap: 5.0.0
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.3.4

System Versions:
dist: ubuntu 22.04 Jammy Jellyfish
locale: utf-8
machine: x86_64
release: 5.15.0-1022-aws
system: Linux
version: Ubuntu 22.04 Jammy Jellyfish

@kTipSSIoYv
Copy link
Author

kTipSSIoYv commented Nov 7, 2022

Adding /custom-config='c:\\salt\\conf\\minion' args to the /usr/lib/python3/dist-packages/salt/utils/cloud.py seems to resolve the issue. Can someone create a PR for this?

Note: I had to create a dummy file before the installation starts. The dummy file will be backed up during the installation and new config file will be created.

This also fixes the issue #63016 because installer uses the pub file from c:\salt\ instead of from c:\programdata\salt project\salt.

        # Create a dummy file so the installer can use. 
        if minion_conf:
            minion_conf_temp = "Temp file"
            salt.utils.smb.put_str(
                salt_config_to_yaml(minion_conf_temp, line_break="\r\n"),
                "salt\\conf\\minion",
                conn=smb_conn,
            )

        if use_winrm:
            winrm_cmd(
                winrm_session,
                "c:\\salttemp\\{}".format(installer),
                ["/S /custom-config='c:\\salt\\conf\\minion'", "/master={}".format(master), "/minion-name={}".format(name)],
            )
        else:
            cmd = "c:\\salttemp\\{}".format(installer)
            args = "/S /custom-config='c:\\salt\\conf\\minion' /master={} /minion-name={}".format(master, name)
            stdout, stderr, ret_code = run_psexec_command(
                cmd, args, host, username, password
            )

            if ret_code != 0:
                raise Exception("Fail installer {}".format(ret_code))

@OrangeDog
Copy link
Contributor

That seems to be the same underlying issue as #62968.

@twangboy
Copy link
Contributor

#63030 should put things in the right location

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior Grains needs-triage Salt-Cloud Windows
Projects
None yet
Development

No branches or pull requests

3 participants