salt-ext-modules-vmware
salt-ext-modules-vmware copied to clipboard
Unable to stop an ESXi service from within a state file
Hello everyone, first of all a description of my environment:
Test environment
OS
[root@getvlsalt02 srv]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
Salt version
[root@getvlsalt02 srv]# rpm -qa|grep salt
salt-3005.1-1.el7.noarch
salt-master-3005.1-1.el7.noarch
salt-minion-3005.1-1.el7.noarch
###VMware extensions
saltext.vmware-22.9.8.0rc1.dist-info
My problem
Explicit invocation
When I invoke (via salt-call) the module manage_service to stop a a service on a specific ESXi (got pillar structure already configured), it works as expected.
[root@getvlsalt02 ~]# salt-call vmware_esxi.manage_service service_name=TSM-SSH host_name=myhostname.mydomain.lan state=stop
local:
True
[root@getvlsalt02 ~]# salt-call vmware_esxi.list_services service_name=TSM-SSH host_name=myhostname.mydomain.lan
local:
----------
myhostname.mydomain.lan:
----------
TSM-SSH:
----------
startup_policy:
off
state:
stopped
[root@getvlsalt02 ~]# salt-call vmware_esxi.manage_service service_name=TSM-SSH host_name=myhostname.mydomain.lan state=start
local:
True
[root@getvlsalt02 ~]# salt-call vmware_esxi.manage_service service_name=TSM-SSH host_name=myhostname.mydomain.lan startup_policy=on
local:
True
[root@getvlsalt02 ~]# salt-call vmware_esxi.list_services service_name=TSM-SSH host_name=myhostname.mydomain.lan
local:
----------
myhostname.mydomain.lan:
----------
TSM-SSH:
----------
startup_policy:
on
state:
running
From within a state file
If I try, instead, to invoke the service management command from within a state file, I can modify the service's startup_policy but the state stays running.
The state file
[root@getvlsalt02 srv]# cat salt/new3.sls
setup_services_3a:
module.run:
- name: vmware_esxi.manage_service
- service_name: TSM-SSH
- host_name: {{ pillar['mytarget']['hostname'] }}
- startup_policy: off
- state: stop
list_service_3a:
module.run:
- name: vmware_esxi.list_services
- service_name: TSM-SSH
- host_name: {{ pillar['mytarget']['hostname'] }}
The invocation of above described state
[root@getvlsalt02 srv]# salt-call state.apply new3
local:
----------
ID: setup_services_3a
Function: module.run
Name: vmware_esxi.manage_service
Result: True
Comment: Module function vmware_esxi.manage_service executed
Started: 11:26:55.643790
Duration: 11281.336 ms
Changes:
----------
ret:
True
----------
ID: list_service_3a
Function: module.run
Name: vmware_esxi.list_services
Result: True
Comment: Module function vmware_esxi.list_services executed
Started: 11:27:06.925574
Duration: 9191.757 ms
Changes:
----------
ret:
----------
myhostname.mydomain.lan:
----------
TSM-SSH:
----------
startup_policy:
off
state:
running
Summary for local
------------
Succeeded: 2 (changed=2)
Failed: 0
------------
Total states run: 2
Total run time: 20.473 s