Saltstack [SOLVED]: SaltStack – change file permissions

Saltstack [SOLVED]: SaltStack – change file permissions

Home Forums Automation Tools Saltstack Tutorials Saltstack [SOLVED]: SaltStack – change file permissions

Tagged: ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #65147

    Cloudy Point
    Keymaster

    QuestionQuestion

    I need to change file permissions in Linux using SaltStack.

    For directory I can use file.directory function, for example:

    file.directory:
      - user: root
      - group: root
      - mode: 400
    

    But what should I use for files?

    I can use:

      file.managed:
        - user: root
        - group: root
        - mode: 444
    

    And it works but I have a warning message:

    [WARNING ] State for file: /boot/grub/grub.cfg – Neither ‘source’ nor
    ‘contents’ nor ‘contents_pillar’ nor ‘contents_grains’ was defined,
    yet ‘replace’ was set to ‘True’. As there is no source to replace the
    file with, ‘replace’ has been set to ‘False’ to avoid reading the file
    unnecessarily.

    It expects a source directive, but I don’t want to download the file to the minion, I just need to change file permissions.

    file.exists function doesn’t have a user, group and mode directives.

    What options do I have?

    #65149

    Cloudy Point
    Keymaster

    Accepted AnswerAnswer

    The warning message you get pretty much says it all. If you specify replace: False the message will be gone:

    file.managed:
    - user: root
    - group: root
    - mode: 444
    - replace: False
    

    Doing cmd.run would obviously remove this message, but it’s too generic and is more like a workaround here. More salty approach would be to use file.managed state because this is what it was designed for.

    Source: http://stackoverflow.com/questions/42509578/saltstack-change-file-permissions
    Author: frizz
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.