Ansible
在ansible playbook中,如果塊任務中已經存在文件,如何跳過任務?
我有這樣的任務:
- name: install jetbrains toolbox changed_when: block: - name: download toolbox get_url: url: 'https://download.jetbrains.com/toolbox/jetbrains-toolbox-{{ toolbox_version }}.tar.gz' dest: /tmp/toolbox.tar.gz - name: open toolbox unarchive: src: /tmp/toolbox.tar.gz dest: /opt/jetbrains-toolbox args: creates: /opt/jetbrains-toolbox
但它會產生一個錯誤:
ERROR! 'changed_when' is not a valid attribute for a Block
/opt/jetbrains-toolbox.tar.gz
如果/opt/jetbrains-toolbox
已經存在,我如何跳過跳過下載的下載下載?
--- - name: register status of /tmp/toolbox.tar.gz stat: path: /tmp/toolbox.tar.gz register: toolbox_path - name: install jetbrains toolbox # check if toolbox_path is a regular file when: "not toolbox_path.stat.exists" block: - name: download toolbox get_url: url: "https://download.jetbrains.com/toolbox/jetbrains-toolbox-{{ toolbox_version }}.tar.gz" dest: /tmp/toolbox.tar.gz - name: open toolbox unarchive: src: /tmp/toolbox.tar.gz dest: /opt/jetbrains-toolbox
您可能還想在下載中包含校驗和,因為您知道要下載的確切版本。