当前位置:  开发笔记 > 前端 > 正文

Ansible - 查找和设置权限,包括粘滞位

如何解决《Ansible-查找和设置权限,包括粘滞位》经验,为你挑选了1个好方法。

使用Ansible 2.1.4.0

是否可以sticky bit在1个任务中设置和文件夹权限?

例;

# Shell is used over find module cause symlink breaks and performance

- name: Find directories in /tmp which are not valid
  shell: find
    /tmp/test -type d
    \( ! -user root -o ! -group root -o ! -perm 775 \)
  register: find1

- name: Set 775 for found directories
  file:
    path: "{{ item }}"
    owner: root
    group: vagrant
    mode: 0775
    state: directory
  with_items: "{{ findPermission1.stdout_lines | default([]) }}"


- name: Find directories in /tmp which have no sticky bit
  shell: find
    /tmp/test -type d
    \! -perm /1000
  changed_when: false
  register: find2

- name: Set permissions for found directories
  file:
    path: "{{ item }}"
    owner: root
    group: vagrant
    mode: g+s
    state: directory
    recurse: no #cause it already found recurse
  with_items: "{{ find.stdout_lines | default([]) }}"

现在,我必须有2个不同的任务来设置权限.但是他们互相覆盖.

目标:在一项任务中将权限设置为775和g + s.



1> Kevin C..:

找到了. http://docs.ansible.com/ansible/file_module.html

  - name: Set sticky bit + 775 for directory
    file:
      path: /tmp/test
      owner: root
      group: vagrant
      mode: u=rwx,g=rwx,o=rx,g+s
      state: directory

推荐阅读
手机用户2402852387
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有