with_items and when

31 views
Skip to first unread message

Sudhir Kumar

unread,
Oct 25, 2017, 8:17:13 AM10/25/17
to Ansible Project
Hi,

Basically would like to check if file is present on remote system or not. If not present, then create one, otherwise skip this step. 
 
 - name: Checking if files already present
      stat:
       path: "{{ item }}"
      register: file_path
      with_items:
        - /var/abc.key
        - /var/xyz.key
        - /var/spk.key


    - name: Creating files
      file:
       path: "{{ item }}"
       state: touch
       owner: root
       group: named
       mode: 0644
      with_items:
         - /var/abc.key
        - /var/xyz.key
        - /var/spk.key
      when: file_path.stat.exists == False

Any ideas ?






Brian Coca

unread,
Oct 25, 2017, 9:33:18 AM10/25/17
to Ansible Project
- copy: content=' ' dest={{item}} force=no
with_items:
- /var/abc.key
...


--
----------
Brian Coca

Sudhir Kumar

unread,
Oct 26, 2017, 6:21:47 AM10/26/17
to Ansible Project
Thanks Brian.. 
Reply all
Reply to author
Forward
0 new messages