常用ansible语法

  1. 递归mv某个目录下的所有文件
# Copy all files and directories from /usr/share/easy-rsa to /etc/easy-rsa

- name: List files in /usr/share/easy-rsa
  find:
    path: /usr/share/easy-rsa
    recurse: yes
    file_type: any
  register: find_result

- name: Create the directories
  file:
    path: "{{ item.path | regex_replace('/usr/share/easy-rsa','/etc/easy-rsa') }}"
    state: directory
    mode: "{{ item.mode }}"
  with_items:
    - "{{ find_result.files }}"
  when:
    - item.isdir

- name: Copy the files
  copy:
    src: "{{ item.path }}"
    dest: "{{ item.path | regex_replace('/usr/share/easy-rsa','/etc/easy-rsa') }}"
    remote_src: yes
    mode: "{{ item.mode }}"
  with_items:
    - "{{ find_result.files }}"
  when:
    - item.isdir == False

- name: delete the files
 file:
    path: "{{ item.path }}"
    state: absent
  with_items:
    - "{{ find_result.files }}"
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 姓名:陈典佐 学号:19021210755 课程:智慧宇宙新物种的诞生 vi vim 篇 三种模式 正常模式在正常...
    佐_529d阅读 435评论 0 1
  • linux的常用命令以及常用工具 大数据的学习难免要做集群,集群难免用到linux,所以总结常用的linux命令,...
    慕久久阅读 583评论 0 9
  • 1、ls命令 就是list的缩写,通过ls 命令不仅可以查看linux文件夹包含的文件,而且可以查看文件权限(包括...
    zjk_00阅读 378评论 0 1
  • 1.了解什么是绝对路径和相对路径 来自百度经验中的一段解释: 1> 什么是绝对路径: 大家都知道,在我们平时使用...
    c5550ea746f8阅读 3,295评论 0 2
  • 1、命令格式; 如果用户要使用Linux,可通过CLI方式执行命令。在Linux中,一般命令的通用语法格式如下: ...
    徐公不若君之美也阅读 1,201评论 0 1