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] Can't get custom grains sync at provisioning (via salt-cloud) #61946

Closed
1 task done
cavepopo opened this issue Apr 13, 2022 · 8 comments · Fixed by #62056
Closed
1 task done

[BUG] Can't get custom grains sync at provisioning (via salt-cloud) #61946

cavepopo opened this issue Apr 13, 2022 · 8 comments · Fixed by #62056
Labels
Bug broken, incorrect, or confusing behavior Salt-Cloud

Comments

@cavepopo
Copy link
Contributor

cavepopo commented Apr 13, 2022

Description
When provisioning windows VM I'm trying to get a custom grains sync'ed somehow but cannot get it to work.

Setup
I've been trying to get using :

  • salt-cloud config file, hitting this
  • orchestration state + reactor :
# Reactor entry :
- 'salt/cloud/*/deploy_windows':
    - '/srv/reactors/windows_first_start.sls'

# in /srv/reactors/windows_first_start.sls : 
sync_grains:
  local.saltutil.sync_grains:
    - tgt: {{ data['name'] }}

windows_orch:
  runner.state.orchestrate:
    - mods: orch.windows
    - pillar:
        vm_name: {{ data.name }}

# Orchestration states, in orch.windows : 
{% set vm_name = salt.pillar.get('vm_name') %}

wait_waht_for:
  cmd.run:
    - name: sleep 20
 
##### Sync_all to make custom modules available
#####+ https://github.com/saltstack/salt/issues/54452
#
load_my_custom_module:
  module.run:
    - name: saltutil.sync_all
    - refresh: True

orchestrate_windows_first_start:
  salt.state:
    - tgt: '{{ vm_name }}'
    - sls:
      - common.windows

Please be as specific as possible and give set-up details.

  • VM as QEMU hosted on proxmox

Steps to Reproduce the behavior
provision windows QEMU on proxmox host and try to get custom grains available after provisioning

Expected behavior
Getting custom grains available when running orchestration states straight after the provisioning

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)

######### Master's version :

Salt Version:
          Salt: 3004.1
 
Dependency Versions:
          cffi: 1.14.6
      cherrypy: Not Installed
      dateutil: 2.7.3
     docker-py: Not Installed
         gitdb: 2.0.5
     gitpython: 2.1.11
        Jinja2: 2.10
       libgit2: 1.1.0
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 0.5.6
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: 2.20
      pycrypto: 2.6.1
  pycryptodome: 3.6.1
        pygit2: 1.6.1
        Python: 3.7.3 (default, Jan 22 2021, 20:04:44)
  python-gnupg: Not Installed
        PyYAML: 3.13
         PyZMQ: 17.1.2
         smmap: 2.0.5
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.1
 
System Versions:
          dist: debian 10 buster
        locale: utf-8
       machine: x86_64
       release: 5.4.162-1-pve
        system: Linux
       version: Debian GNU/Linux 10 buster

######### Minion's version :

Salt Version:
          Salt: 3004.1

Dependency Versions:
          cffi: 1.14.6
      cherrypy: 18.6.1
      dateutil: 2.8.1
     docker-py: Not Installed
         gitdb: 4.0.7
     gitpython: Not Installed
        Jinja2: 2.10.1
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: 1.1.4
       msgpack: 0.6.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: 2.20
      pycrypto: Not Installed
  pycryptodome: 3.10.1
        pygit2: Not Installed
        Python: 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:08:11) [MSC v.1928 32 bit (Intel)]
  python-gnupg: 0.4.7
        PyYAML: 5.4.1
         PyZMQ: 19.0.0
         smmap: 4.0.0
       timelib: 0.2.4
       Tornado: 4.5.3
           ZMQ: 4.3.2

System Versions:
          dist:
        locale: cp1252
       machine: AMD64
       release: 2021
        system: Windows
       version: 2021 10.0.19041 SP0 Multiprocessor Free

Additional context
Logs from the master while provisioning, I can see the sync_all module is ran but nothing is found to be sync'ed :

                    "__id__": "load_my_custom_module",
                    "__run_num__": 1,
                    "__sls__": "orch.windows",
                    "changes": {
                        "ret": {
                            "beacons": [],
                            "clouds": [],
                            "engines": [],
                            "executors": [],
                            "grains": [],
                            "log_handlers": [],
                            "matchers": [],
                            "modules": [],
                            "output": [],
                            "pillar": [],
                            "proxymodules": [],
                            "renderers": [],
                            "returners": [],
                            "sdb": [],
                            "serializers": [],
                            "states": [],
                            "thorium": [],
                            "utils": []
                        }
                    },
                    "comment": "Module function saltutil.sync_all executed",
                    "duration": 1732.087,
                    "name": "saltutil.sync_all",
                    "result": true,
                    "start_time": "07:45:24.661448"
                },

Custom grains is available to the master :

root@salt-master-01:~# salt-run fileserver.file_list  
- _grains/presentusersgrain.py
[...]

Right after the provisioning I can see there is no present_users grains using grains.ls ...

And I can even sync after the vm is actually provisioned :

root@salt-master-01:~# salt gitlab-runner-win-01  saltutil.sync_grains
gitlab-runner-win-01:
    - grains.presentusersgrain

And see it then :

root@salt-master-01:~# salt gitlab-runner-win-01 grains.ls
gitlab-runner-win-01:
    - biosversion
    - cpu_model
    - cpuarch
    - cwd
    - disks
    - domain
    - efi
    - efi-secure-boot
    - fqdn
    - fqdn_ip4
    - fqdn_ip6
    - fqdns
    - gpus
    - groupname
    - host
    - hwaddr_interfaces
    - id
    - init
    - ip4_interfaces
    - ip6_interfaces
    - ip_interfaces
    - ipv4
    - ipv6
    - kernel
    - kernelrelease
    - kernelversion
    - locale_info
    - localhost
    - manufacturer
    - master
    - mem_total
    - motherboard
    - nodename
    - num_cpus
    - num_gpus
    - os
    - os_family
    - osfinger
    - osfullname
    - osmanufacturer
    - osrelease
    - osrelease_info
    - osservicepack
    - osversion
    - path
    - pending_reboot
    - pid
    - present_users
    - productname
    - ps
[...]
@cavepopo cavepopo added Bug broken, incorrect, or confusing behavior needs-triage labels Apr 13, 2022
@nicholasmhughes
Copy link
Collaborator

It looks like your sync_all is being run at the orchestration level, so it's not targeting vm_name.

Does something like this work?

load_my_custom_module:
  salt.function:
    - tgt: '{{ vm_name }}'
    - name: saltutil.sync_all
    - kwarg:
        refresh: True

@cavepopo
Copy link
Contributor Author

@nicholasmhughes your are right, it's been too long for me, I lost my salt foo, your solution fix it, thanks !

I keep that one open as this is only a workaround, the main goal here is to get the cloud config option to work as expected.

@nicholasmhughes
Copy link
Collaborator

Looking at the code and the documentation, it seems like sync_after_install is not meant to be a boolean... but instead a word representing the completion of a saltutil.sync_ module function showing what you want to sync (all, beacons, etc.)

Can you try setting sync_after_install: all in your cloud config?

If that works, the follow-ups I see are:

  • a comprehensive list of saltutil.sync_ functions should be added to the code and documentation
  • a non-falsey value that doesn't match the list should probably just assume all

@nicholasmhughes
Copy link
Collaborator

@cavepopo , can you take a look at the previous comment and let me know if all as the value fixes the behavior?

@nicholasmhughes
Copy link
Collaborator

@cavepopo , have you been able to test the suggestion above?

@cavepopo
Copy link
Contributor Author

cavepopo commented May 9, 2022

@cavepopo , have you been able to test the suggestion above?

Not yet, I am still using the workaround, but I think I already tried the "all" fix but I'll try tomorrow to be sure and to give a correct feedback

@cavepopo
Copy link
Contributor Author

cavepopo commented May 10, 2022

Hi @nicholasmhughes ,

Unfortunately this (sync_after_install: all) does not work, here is some info from the event bus :

[INFO    ] salt-cloud starting
[INFO    ] Applying map from '/etc/salt/gitlab-runner.map'.
[INFO    ] Calculating dependencies for gitlab-runner
[INFO    ] Creating Cloud VM gitlab-runner
[INFO    ] Configuring cloned VM
[INFO    ] Rendering deploy script: /usr/lib/python3/dist-packages/salt/cloud/deploy/bootstrap-salt.sh
[INFO    ] Connecting to SMB Tree \\<ip>\ADMIN$
[INFO    ] Creating open to PAExec file with delete on close flags
[INFO    ] Disconnecting from SMB Tree \\<ip>\ADMIN$
[INFO    ] Get connection smbprotocol
[INFO    ] Connecting to SMB Tree \\<ip>\ADMIN$
[INFO    ] Creating open to PAExec file with delete on close flags
[INFO    ] Disconnecting from SMB Tree \\<ip>\ADMIN$
[INFO    ] Connecting to SMB Tree \\<ip>\ADMIN$
[INFO    ] Creating open to PAExec file with delete on close flags
[INFO    ] Disconnecting from SMB Tree \\<ip>\ADMIN$
[INFO    ] Connecting to SMB Tree \\<ip>\ADMIN$
[INFO    ] Creating open to PAExec file with delete on close flags
[INFO    ] Disconnecting from SMB Tree \\<ip>\ADMIN$
[INFO    ] Salt installed on gitlab-runner
[INFO    ] Created Cloud VM 'gitlab-runner'
[ERROR   ] There was a query error: 'ImmutableDict' object has no attribute 'update'

@nicholasmhughes
Copy link
Collaborator

@cavepopo , I think PR #62056 might fix the issue. It looks like the code was attempting to update DEFAULT_MASTER_OPTS directly... which is an ImmutableDict. If you'd like to try to patch it in place and test, please let me know the results.

garethgreenaway pushed a commit to garethgreenaway/salt that referenced this issue May 23, 2022
Ch3LL pushed a commit that referenced this issue May 26, 2022
* Making the retry state system feature available when parallel is set to True.

* swapping out using time.sleep Salt function for Python time.sleep.

* Skipping parallel tests on Windows.

* Fixing items, values, and keys functions in the data module.  Moving integration to functional tests.  Converting unit test over to pytest.

* adding changleog.

* fixes #62044 add ignore_missing to file.comment state

* fixes #61662 fix file.comment reports changes in test mode

* add 61662.fixed changelog

* add final test mode run after comment is successful

* fix uncomment_regex

* fix uncomment_regex

* Try not to trigger the GLIBC race condition.

See https://sourceware.org/bugzilla/show_bug.cgi?id=19329

Fixes #62071

Signed-off-by: Pedro Algarvio <[email protected]>

* Add missing CLI example to ``network.fqdns``

Signed-off-by: Pedro Algarvio <[email protected]>

* Sleep between submitting new jobs to thread pool

Signed-off-by: Pedro Algarvio <[email protected]>

* Sleep before trying to resolve instead

Signed-off-by: Pedro Algarvio <[email protected]>

* Shorter sleeps

* fixes #61944 fixed backslash literal bytestring

* When states are running in parallel, ensure that the total run time produced by the highstate outputter takes that into account.

* removing unrelated change

* Adding changelog.

* Skip parallel test on Windows.

* skip pdbedit unit tests on ubuntu 2204 because md4 is not supported as a hash type

* refresh db at the beginning for destructive aptpkg functional tests

* fix failing test_pkgrepo_managed_absent and actually capture and keep signed-by information in salt/modules/aptpkg.py custom implementation of apt repository management

* Update tests/unit/modules/test_pdbedit.py

Co-authored-by: Pedro Algarvio <[email protected]>

* Disable hack to force allowing forking on macOS

* Use the newer nox platforms file which installs Py3.9

Signed-off-by: Pedro Algarvio <[email protected]>

* Support macOS defaulting to spawn as the default multiprocessing method

* Remove unused attribute

* Switch to ``salt.utils.platform.spawning_platform()``

Signed-off-by: Pedro Algarvio <[email protected]>

* Reconstruct client instances on spawning platforms

* Also skip this test for now on macOS

Signed-off-by: Pedro Algarvio <[email protected]>

* Reconstruct the ``State`` class on spawned processes.

Signed-off-by: Pedro Algarvio <[email protected]>

* Force a reference to ``salt.ext.tornado.iostream.StreamClosedError`` to avoid ``NameError`` issues

Signed-off-by: Pedro Algarvio <[email protected]>

* Skip, for now, problematic tests on spawning platforms

Signed-off-by: Pedro Algarvio <[email protected]>

* DeltaProxy minions do not work on spawning platforms

Signed-off-by: Pedro Algarvio <[email protected]>

* Avoid a ``NameError`` when failing to initialize the process list

Signed-off-by: Pedro Algarvio <[email protected]>

* Use Python 3.9 on macOS

Signed-off-by: Pedro Algarvio <[email protected]>

* Drop requirements on Darwin for Py<3.9

Signed-off-by: Pedro Algarvio <[email protected]>

* Same test run timeout as windows

Signed-off-by: Pedro Algarvio <[email protected]>

* Don't shell out! Access the database directly and properly escape values.

Signed-off-by: Pedro Algarvio <[email protected]>

* Fixes for the new macOS Catalina and BigSur CICD images

Signed-off-by: Pedro Algarvio <[email protected]>

* Migrate ``integration.modules.test_mac_pkgutil`` to PyTest and functional tests.

Fixes #60819

Signed-off-by: Pedro Algarvio <[email protected]>

* Add changelog for #57742

Fixes #57742

Signed-off-by: Pedro Algarvio <[email protected]>

* Add changelog entry.

Fixes #55847

Signed-off-by: Pedro Algarvio <[email protected]>

* initial Proxy Module

* inital pass of restconf states

* adding codeauthor

* adding restconf module

* doc update

* doc update

* doc update

* add requirements chefk to states module

* doc update

* doc update

* doc update

* add changelog entry

* Update salt/proxy/restconf.py

Co-authored-by: Wayne Werner <[email protected]>

* Update salt/proxy/restconf.py

Co-authored-by: Wayne Werner <[email protected]>

* remove noqa statements

* docs update & opts defaults

* docs update

* error checks + https transport method

* docs update

* docs update

* doing a fix for commit check

* adding test and updating modules

* removing old code

* DRY

* docs update

* output updates

* prepping for deepdiff switch

* states testing

* more tests

* changed changelog from fixed to added

* force pre-commit checks

* new style of diff output that is readable

* updating tests and output

* updating output style to make YAML diff more readable

* add test for restconf module

* adjusting based on pr review

* adjusting based on pr review

* adjusting true/false verify based on pr review

* change uri to path and clean args list

Co-authored-by: Wayne Werner <[email protected]>

* adjusting uri to path based on pr review

* adjusting capabilities path based on pr review

* Update salt/modules/restconf.py

Co-authored-by: Wayne Werner <[email protected]>

* adjusting val based on pr review

* caps to confirm to RFC 8040

* WIP: refactor based on feedback

* WIP: changed results to be any kind of falsey val

* linting - pre-commit

* updating docs

* Update salt/states/restconf.py

Co-authored-by: Wayne Werner <[email protected]>

* updating style

* fixes for lint and nox pass

* fixing

* blacken

* Update restconf.py

* add cli examples

* change logging type

* add pytest skip for ordereddict issue with legacy python

* add sys library for pytest mark skipif check

* pre-commit fixes

* Update salt/proxy/restconf.py

Co-authored-by: Pedro Algarvio <[email protected]>

* Update salt/states/restconf.py

Co-authored-by: Pedro Algarvio <[email protected]>

* Update tests/pytests/unit/modules/test_restconf.py

Co-authored-by: Pedro Algarvio <[email protected]>

* Update tests/pytests/unit/states/test_restconf.py

Co-authored-by: Pedro Algarvio <[email protected]>

* Update tests/pytests/unit/proxy/test_restconf.py

Co-authored-by: Pedro Algarvio <[email protected]>

* pre-commit fix

* update logging

* Update restconf.py

* some rest apis dont follow the standard correctly (cisco) and need another header

* fixes #61946 sync_after_install immutabledict error

* add configurable sync sleep for create

* add testing around the particular sync command called

* Adds the ability to get file version information on Windows

- Adds file.version that will get just the version
- Adds file.version_details to get additional information
- Adds tests
- Adds changelog

@amalaguti originally submitted a PR for this: #59770, but he has
since deleted his branch. Recognizing his contribution here.

* Update states.chef for version 16.x and 17.x Chef Infra Client output

* Support previous Chef version plus version 16.x and 17.x output.

* Remove legacy chef unit test

* Add unit tests for chef state

These tests cover the entire state, but are only concerned with the
ret["result"] of the outputs. It would be a good idea to test other
outputs as well - these tests could be modified to include assertions
about the other parts of ret. (Obviously they would need to be slightly
renamed. Maybe to `..._return_expected_ret`

* Update salt-bootstrap to 2022.03.15 release

* Update state.py

Fixing lint.

* Running pre-commit manually.

* swap out salt.utils.platform.is_windows for salt.utils.platform.spawning_platform.  Bump up duration for test_retry_option_success_parallel to 30 seconds to account for test running on Mac OS.

Co-authored-by: Megan Wilhite <[email protected]>
Co-authored-by: nicholasmhughes <[email protected]>
Co-authored-by: Pedro Algarvio <[email protected]>
Co-authored-by: emmadionne1 <[email protected]>
Co-authored-by: MKLeb <[email protected]>
Co-authored-by: Caleb Beard <[email protected]>
Co-authored-by: Pedro Algarvio <[email protected]>
Co-authored-by: Jamie Murphy <[email protected]>
Co-authored-by: Jamie (Bear) Murphy <[email protected]>
Co-authored-by: Jamie Murphy <[email protected]>
Co-authored-by: Wayne Werner <[email protected]>
Co-authored-by: Cassandra Durnford <[email protected]>
Co-authored-by: Jamie Murphy <[email protected]>
Co-authored-by: Jamie (Bear) Murphy <[email protected]>
Co-authored-by: Twangboy <[email protected]>
Co-authored-by: Eric Ham <[email protected]>
Co-authored-by: Wayne Werner <[email protected]>
Co-authored-by: krionbsd <[email protected]>
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 Salt-Cloud
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants