1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/test/integration/targets/file_lock/test_filelock.yml

46 lines
1.1 KiB
YAML
Raw Normal View History

---
- hosts: lockhosts
gather_facts: no
vars:
lockfile: ~/ansible_testing/lock.test
tasks:
- name: Remove lockfile
file:
path: '{{ lockfile }}'
state: absent
run_once: yes
- name: Write inventory_hostname to lockfile concurrently
lineinfile:
path: '{{ lockfile }}'
line: '{{ inventory_hostname }}'
create: yes
state: present
- debug:
msg: File {{ lockfile }} has {{ lines|length }} lines for {{ ansible_play_batch|length }} instances
vars:
lines: "{{ lookup('file', lockfile).split('\n') }}"
run_once: yes
- name: Assert we get the expected number of lines
assert:
that:
- lines|length == ansible_play_batch|length
vars:
lines: "{{ lookup('file', lockfile).split('\n') }}"
run_once: yes
- name: Check lockfile for inventory_hostname entries
lineinfile:
path: '{{ lockfile }}'
line: '{{ inventory_hostname }}'
state: present
register: check_lockfile
- name: Assert locking results
assert:
that:
- check_lockfile is not changed
- check_lockfile is not failed