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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

manage multiple files in same state #52130

Closed
wolfpackmars2 opened this issue Mar 11, 2019 · 3 comments
Closed

manage multiple files in same state #52130

wolfpackmars2 opened this issue Mar 11, 2019 · 3 comments
Labels
Bug broken, incorrect, or confusing behavior Documentation Relates to Salt documentation P4 Priority 4
Milestone

Comments

@wolfpackmars2
Copy link
Contributor

wolfpackmars2 commented Mar 11, 2019

Edit

Turns out the original issue was caused by a typo 馃槉. There may still be an opportunity to improve the docs by including a working example using the names declaration in a file.managed state.

Description of Issue/Question

According to the docs, it should be possible to manage multiple files in one state using the 'names' parameter. However, the results in an error "Rendering SLS failed: mapping values are not allowed in this context"

Related #4508 - specifically shorawitz commented on Feb 12, 2016

The docs may be misleading and may need to be reviewed or a good, working example of managing multiple files using the names parameter should be added to the docs.

Related documentation links:
https://docs.saltstack.com/en/2019.2/ref/states/all/salt.states.file.html#operations-on-regular-files-special-files-directories-and-symlinks

The names parameter, which is part of the state compiler, can be used to expand the contents of a single state declaration into multiple, single state declarations. Each item in the names list receives its own individual state name and is converted into its own low-data structure. This is a convenient way to manage several files with similar attributes.

There is more documentation about this feature in the Names declaration section of the Highstate docs.

Setup

Using either state:

salt_master_configuration_files:
  file:
    - managed
    - user: root
    - group: root
    - mode: '0644'
    - names:
      - /etc/salt/master.d/master.conf:
        - source: salt://saltmaster/master.conf
      - /etc/salt/minion.d/minion-99.conf
        - source: salt://saltmaster/minion.conf

or

salt_master_configuration_files:
  file.managed:
    - user: root
    - group: root
    - mode: '0644'
    - names:
      - /etc/salt/master.d/master.conf:
        - source: salt://saltmaster/master.conf
      - /etc/salt/minion.d/minion-99.conf
        - source: salt://saltmaster/minion.conf

Steps to Reproduce Issue

Use state included in "setup" and run highstate

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: 2.0.3
gitpython: 2.1.8
ioflo: Not Installed
Jinja2: 2.10
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: 1.0.7
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: 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
python-gnupg: 0.4.1
PyYAML: 3.12
PyZMQ: 16.0.2
RAET: Not Installed
smmap: 2.0.3
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-46-generic
system: Linux
version: Ubuntu 18.04 bionic

@wolfpackmars2
Copy link
Contributor Author

soooo... typos, they'll get you every time.

Managing multiple files in the same state DOES work, if you format the state properly.

Both of the following work:

salt_master_configuration_files:
  file:
    - managed
    - user: root
    - group: root
    - mode: '0644'
    - names:
      - /etc/salt/master.d/master.conf:
        - source: salt://saltmaster/master.conf
      - /etc/salt/minion.d/minion-99.conf
        - source: salt://saltmaster/minion.conf

and

salt_master_configuration_files:
  file.managed:
    - user: root
    - group: root
    - mode: '0644'
    - names:
      - /etc/salt/master.d/master.conf:
        - source: salt://saltmaster/master.conf
      - /etc/salt/minion.d/minion-99.conf
        - source: salt://saltmaster/minion.conf

Although this has been resolved, I think that adding an example to the docs will be beneficial.

@Ch3LL
Copy link
Contributor

Ch3LL commented Mar 11, 2019

sounds like a good idea. Did you want to try to add this to the docs? You would just need to update the salt/states/file.py file with the example.

@Ch3LL Ch3LL added Documentation Relates to Salt documentation Bug broken, incorrect, or confusing behavior P4 Priority 4 labels Mar 11, 2019
@Ch3LL Ch3LL added this to the Approved milestone Mar 11, 2019
wolfpackmars2 added a commit to wolfpackmars2/salt that referenced this issue Mar 12, 2019
@Ch3LL Ch3LL closed this as completed Mar 13, 2019
Ch3LL pushed a commit to Ch3LL/salt that referenced this issue Mar 14, 2019
@KyleBourdlaies
Copy link

KyleBourdlaies commented Mar 8, 2022

typo(s) still abound in the above examples:

salt_master_configuration_files:
  file:
    - managed
    - user: root
    - group: root
    - mode: '0644'
    - names:
      - /etc/salt/master.d/master.conf:
        - source: salt://saltmaster/master.conf
      - /etc/salt/minion.d/minion-99.conf:   <------ ***
        - source: salt://saltmaster/minion.conf

*** don't omit this second colon or you'd get failed: mapping values are not allowed in this context

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 Documentation Relates to Salt documentation P4 Priority 4
Projects
None yet
Development

No branches or pull requests

3 participants