Azer H
Azer H

Reputation: 31

Ansible playbook with serial > 1 and run_once

I am writing simple two task ansible playbook to download update file from internet and push it to managed servers, something similar to:

- hosts: all
  serial: 10

  tasks:
  - name: Download update file
    get_url: url=http://f.q.d.n/path/to/file dest=/tmp/
    connection: local
    run_once: true

  - name: Copy update file to all servers
    copy: src=/tmp/file dest=/path/to/file mode="..."

First task supposed to run just once on localhost, the rest run in 10 serial batches. However according to ansible documentation, tasks marked as "run_once" will be ran on one host in each serial batch.

I can't use workaround mentioned in documentation, using inventory_hostname in conditional, since actual target hosts may be different, e.g. restricted with --limit etc.
What would be proper way to design this playbook? Is pre_task of any use here ?

Upvotes: 2

Views: 5439

Answers (1)

helloV
helloV

Reputation: 52433

- hosts: localhost

  tasks:
  - name: Download update file
    get_url: url=http://f.q.d.n/path/to/file dest=/tmp/


- hosts: all
  serial: 10

  tasks:
  - name: Copy update file to all servers
    copy: src=/tmp/file dest=/path/to/file mode="..."

Upvotes: 2

Related Questions