常用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 }}"

你可能感兴趣的:(常用ansible语法)