How to make Ansible run one certain task only on one host?

For any host (with defaults it will match the first on the list):

- name: "run on first found host"
  shell: this_command_should_run_on_one_host
  run_once: true

For a specific host:

- name: "run on that_one_host host"
  shell: this_command_should_run_on_one_host
  when: ansible_hostname == 'that_one_host'

Or inventory_hostname (hostname as defined in the Ansible inventory) instead of ansible_hostname (hostname as defined on the target machine), depending on which name you want to use.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)