9.7管理文件属性

1.查看file模块的帮助信息

其中,path参数定义了文件的路径,owner参数定义了文件所有者,group参数定义了文件所属组,mode参数定义了文件权限,src参数定义了源文件的路径,dest参数定义了目标文件的路径,state参数则定义了文件类型。
[root@dsrw ~]# ansible-doc file
EXAMPLES:

- name: Change file ownership, group and permissions
  file:
    path: /etc/foo.conf
    owner: foo
    group: foo
    mode: '0644'
- name: Create a directory if it does not exist
  file:
    path: /etc/some_directory
    state: directory
mode: '0755'

2.创建文件操作剧本

[root@dsrw ~]# vim chmod.yml
---
- name: 管理文件属性
  hosts: test
  tasks:
    - name: one
      file:
         path: /dsrw
         state: directory
         owner: root
         group: root
         mode: '2775'
         
    - name: two
      file:
         src: /dsrw
         dest: /dsrwcom
         state: link

3.执行剧本

[root@dsrw ~]# ansible-playbook chmod.yml

PLAY [管理文件属性] ******************************************************************

TASK [Gathering Facts] *********************************************************
ok: [192.168.1.12]

TASK [one] *********************************************************************
changed: [192.168.1.12]

TASK [two] *********************************************************************
changed: [192.168.1.12]

PLAY RECAP *********************************************************************
192.168.1.12               : ok=3    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

4.进入test组的主机中查看

[root@dsrw ~]# ls -ld /dsrw
drwxrwsr-x. 2 root root 6 Dec 24 22:11 /dsrw
[root@dsrw ~]# ls -ld /dsrwcom
lrwxrwxrwx. 1 root root 5 Dec 25 11:39 /dsrwcom -> /dsrw
© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称

    请登录后查看评论内容