True or false debug msg

16 views
Skip to first unread message

Dimitri Yioulos

unread,
Feb 17, 2017, 11:35:11 AM2/17/17
to Ansible Project
All,

Probably a crummy subject line, but here's what I'm trying to do:  I want my debug message to return "file exists" or file doesn't exist.  Here's my playbook, so far:

---

- hosts: all
  gather_facts: false

  vars:
    file: lmcfg.txt

  tasks:

    - name: gather information
      win_stat:
        path: E:\LM\{{ file}}
      register: file_info

    - name: check if file name exists
      debug: msg='File {{ file }} exists'
      when: file_info.stat.exists == True

I don't know how to add a piece to return "file doesn't exist" if, well, the file doesn't exist.  Help much appreciated.

Stankovic, Marko

unread,
Feb 17, 2017, 11:47:24 AM2/17/17
to ansible...@googlegroups.com
Hi,

You can use jinja2 template:

- debug:
msg: "File {% if file_info.stat.exists %}exists{% else %}doesn't exist{% endif %}."

More info:
http://jinja.pocoo.org/docs/templates/

Cheers,
Marko
CONFIDENTIALITY NOTICE: This message is the property of International Game Technology PLC and/or its subsidiaries and may contain proprietary, confidential or trade secret information. This message is intended solely for the use of the addressee. If you are not the intended recipient and have received this message in error, please delete this message from your system. Any unauthorized reading, distribution, copying, or other use of this message or its attachments is strictly prohibited.

Dimitri Yioulos

unread,
Feb 17, 2017, 12:47:57 PM2/17/17
to Ansible Project
Marko,

Perfect - thanks!

Dimitri
Reply all
Reply to author
Forward
0 new messages