---
- name: stat
hosts: all
tasks:
- name: Checking File Existence
stat:
path: "/etc/hosts"
register: existence
- name: Debug File Existence
debug:
var: existence
verbosity: 0
- name: Report If File Exists
debug:
msg: Exists
when: existence.stat.exists
- name: Report a Missing File
debug:
msg: does not exists
when: not existence.stat.exists
- name: Task name
debug:
msg: "The file or directory exists"
when: register_name.stat.exists and register_name.stat.isdir
- name: Task name
stat:
path: [path to the file or directory you want to check]
register: register_name
- name: Task name 2
file:
path: [path to the file you want to create]
state: touch
when: not register_name.stat.exists
---
- name: stat
hosts: gitlab-runner
tasks:
- name: pppppp
stat:
path: /etc/timezone
get_statsum: yes
register: stat_timezone
- debug:
var: stat_timezone
- hosts: gitlab
tasks:
- name: Check File Of gitlab
stat:
path: /etc/timezone
get_checksum: yes
register: stat_timezone
when: ansible_ssh_host == 'gitlab'
- debug: var=stat_timezone