Repository navigation
Description
The following error occurs:
[DEBUG ] An exception occurred in this state: string indices must be integers
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/salt/state.py", line 1933, in call
**cdata['kwargs'])
File "/usr/lib/python3/dist-packages/salt/loader.py", line 1939, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python3/dist-packages/salt/states/file.py", line 3932, in recurse
keep.update(_gen_keep_files(name, require))
File "/usr/lib/python3/dist-packages/salt/states/file.py", line 591, in _gen_keep_files
if low['name'] == comp['file'] or low['__id__'] == comp['file']:
TypeError: string indices must be integers
[ERROR ] An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/salt/state.py", line 1933, in call
**cdata['kwargs'])
File "/usr/lib/python3/dist-packages/salt/loader.py", line 1939, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python3/dist-packages/salt/states/file.py", line 3932, in recurse
keep.update(_gen_keep_files(name, require))
File "/usr/lib/python3/dist-packages/salt/states/file.py", line 591, in _gen_keep_files
if low['name'] == comp['file'] or low['__id__'] == comp['file']:
TypeError: string indices must be integersThis occurs specifically when the state name in the formula starts with:
p_files_Setup
formula/p/files.sls
{%- set files = salt['pillar.get']('p:files') -%}
{%- if files.recurse is defined %}
{%- for id, recurse_option in files.recurse.items() %}
p_files_recurse_{{ id }}:
file.recurse:
{%- for key, value in recurse_option.items() %}
{%- if value is string %}
- {{ key }}: '{{ value }}'
{%- else %}
- {{ key }}: {{ value }}
{%- endif %}
{%- endfor %}
{%- endfor %}
{%- endif -%}env/dev/top.sls
dev:
test:
- p.filespillar/dev/test.sls
p:
files:
recurse:
test_recurse_one:
name: /test1
source: salt://files/test1
dir_mode: 0750
file_mode: 0640
user: root
group: root
test_recurse_two:
name: /test2
source: salt://files/test2
require:
- p_files_recurse_test_recurse_one
dir_mode: 0755
file_mode: 0444
user: root
group: root
clean: TrueRunning a highstate test produces the following error:
----------
ID: p_files_recurse_test_recurse_two
Function: file.recurse
Name: /test2
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/salt/state.py", line 1933, in call
**cdata['kwargs'])
File "/usr/lib/python3/dist-packages/salt/loader.py", line 1939, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python3/dist-packages/salt/states/file.py", line 3932, in recurse
keep.update(_gen_keep_files(name, require))
File "/usr/lib/python3/dist-packages/salt/states/file.py", line 591, in _gen_keep_files
if low['name'] == comp['file'] or low['__id__'] == comp['file']:
TypeError: string indices must be integers
Started: 23:43:35.589186
Duration: 324.333 ms
Changes:Steps to Reproduce Issue
Run as is above. The error will be triggered.
However, changing the name of the state ID in the formula fixes the issue. I'm guessing I hit some internally used variable in salt during the highstate process?
Fix
Change the p_files_ to anything else, ala perms. No other changes (even formula name changes) are needed:
formula/p/files.sls
{%- set files = salt['pillar.get']('p:files') -%}
{%- if files.recurse is defined %}
{%- for id, recurse_option in files.recurse.items() %}
perms_recurse_{{ id }}:
file.recurse:
{%- for key, value in recurse_option.items() %}
{%- if value is string %}
- {{ key }}: '{{ value }}'
{%- else %}
- {{ key }}: {{ value }}
{%- endif %}
{%- endfor %}
{%- endfor %}
{%- endif -%}pillar/dev/test.sls
p:
files:
recurse:
test_recurse_one:
name: /test1
source: salt://files/test1
dir_mode: 0750
file_mode: 0640
user: root
group: root
test_recurse_two:
name: /test2
source: salt://files/test2
require:
- perms_recurse_test_recurse_one
dir_mode: 0755
file_mode: 0444
user: root
group: root
clean: TrueRe-running the highstate will now successfully run. My guess is there a namespace collision using files. I haven't seen this happen using other pillar keys with the same name as the formula.
Versions Report
(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)
minion
$ salt-minion --versions-report
Salt Version:
Salt: 2019.2.0
Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 2.6.1
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
Jinja2: 2.10
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.5.6
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 3.6.8 (default, Jan 14 2019, 11:02:34)
python-gnupg: 0.4.1
PyYAML: 3.12
PyZMQ: 16.0.2
RAET: Not Installed
smmap: Not Installed
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.2.5
System Versions:
dist: Ubuntu 18.04 bionic
locale: UTF-8
machine: x86_64
release: 4.15.0-54-generic
system: Linux
version: Ubuntu 18.04 bionicmaster
$ salt-master --versions-report
Salt Version:
Salt: 2019.2.0
Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 2.5.3
docker-py: Not Installed
gitdb: 2.0.0
gitpython: 2.1.1
ioflo: Not Installed
Jinja2: 2.9.4
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.4.8
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 3.5.3 (default, Sep 27 2018, 17:25:39)
python-gnupg: Not Installed
PyYAML: 3.12
PyZMQ: 16.0.2
RAET: Not Installed
smmap: 2.0.1
timelib: Not Installed
Tornado: 4.4.3
ZMQ: 4.2.1
System Versions:
dist: debian 9.9
locale: UTF-8
machine: x86_64
release: 4.9.0-9-amd64
system: Linux
version: debian 9.9
Activity
[-]specific state ID in formula causes TypeError during highstate.[/-][+]Specific state ID in formula causes TypeError during highstate.[/+]r-pufky commentedon Jul 5, 2019
Creating a separate formula SLS file to use for one of the cases resolves this error.
Fix TypeError in file clean when a require ID contains "file"
Fix TypeError in file clean when a require ID contains "file"
Fix TypeError in file clean when a require ID contains "file"
Fix TypeError in file clean when a require ID contains "file"