--- - hosts: lockhost00 vars: lockfile: ~/ansible_testing/lock_timeout.test gather_facts: no tasks: - name: Remove lockfile file: path: '{{ lockfile }}' state: absent run_once: yes - name: Create lockfile lineinfile: line: '{{ inventory_hostname }}' path: '{{ lockfile }}' state: present create: yes - name: Lock lockfile with lockf and sleep 20s command: python args: stdin: | import time from ansible.module_utils.common.file import open_locked with open_locked('{{ lockfile | expanduser }}') as fd: time.sleep(20) async: 60 poll: 0 register: flock_waiter - name: Remove inventory_hostname line from lockfile lineinfile: path: '{{ lockfile }}' line: '{{ inventory_hostname }}' state: absent ignore_errors: yes register: rm_line - name: Assert that removal of inventory_hostname from lockfile failed assert: that: - rm_line is failed - name: Wait for flock job to finish async_status: jid: '{{ flock_waiter.ansible_job_id }}' register: job_result until: job_result.finished retries: 30 - name: Inventory_hostname in lockfile lineinfile: path: '{{ lockfile }}' line: '{{ inventory_hostname }}' state: present register: check_line - name: Assert that lockfile is unchanged assert: that: - check_line is not changed - check_line is not failed