Checking file permission using stat.mode

44 views
Skip to first unread message

Joseph Gill

unread,
Mar 14, 2016, 10:32:49 AM3/14/16
to Ansible Project
Would anyone have the syntax of stat.mode?  I'm trying to check the permissions of a file using ansible 1.9.4 but I''m getting the error:

     fatal: [USSLTCSNL5039.solutions.glbsnet.com] => error while evaluating conditional: foo_conf_file.stat.mode == '0600'

     FATAL: all hosts have already failed -- aborting


Thank you


---
- hosts: myservers
  remote_user: deploy
  become: yes
  become_method: sudo
  vars:
   FOO_CONF: /tmp/foo.conf

# Check for the existance of /tmp/foo.conf
# place the results into foo_conf_file
# check "{{ FOO_CONF }}".stat.exists

  tasks:
  - name: Check file
    stat: path="{{ FOO_CONF }}"
    register: foo_conf_file
  - debug: msg="Oops File does not exist"
    when: foo_conf_file.stat.exists == False
  - debug: msg="Check permissions"
    when: foo_conf_file.stat.mode == '0600'

Reply all
Reply to author
Forward
0 new messages