Hi,
I need to run jib on one host from the hosts in playbook. To distribute
it, should be random host. But as many time as I run the playbook,
always the first host is chosen. Please, what do I wrong? Right now ,
there are only two hosts in the list. See sample playbook.
ansible 2.2.1.0
- hosts: jobs
vars:
lock_file: /tmp/test.lock
pre_tasks:
- name: "create lock file"
file:
path: "{{ lock_file }}"
mode: 0600
owner: root
group: root
state: touch
tasks:
- set_fact:
job_host: "{{ ansible_play_batch|random }}"
run_once: True
delegate_to: '127.0.0.1'
- name: "do action on one host"
file:
path: "{{ lock_file }}.xxx"
mode: 0600
owner: root
group: root
state: touch
run_once: True
delegate_to: "{{ job_host }}"
post_tasks:
- name: "remove lock file"
file:
path: "{{ lock_file }}"
state: absent
thanks
Peter