2017-04-25 101 views

回答

1

關鍵是要使用command模塊的creates參數,它告訴Ansible在給定路徑存在時不要重新運行該命令。這裏是一個示例劇本:

--- 
- hosts: all 
    vars: 
    - svn_repositories: ['test1', 'test2'] 
    - svn_data_dir: /var/svn 
    tasks: 
    - name: Create missing svn repositories 
     command: "svnadmin create '{{svn_data_dir}}/{{item}}'" 
     args: 
     creates: "{{svn_data_dir}}/{{item}}/README.txt" 
     with_items: "{{svn_repositories}}"