FreeKB - Ansible connection parameter
Ansible - connection parameter

By default, Ansible performs tasks on managed node (e.g. target system). The connection parameter with the local flag is used to perform a task on the control node (that's the Ansible server) instead of on the managed node (e.g. target system). In this example, the ssh-keyscan command is invoked on the control node.

---
- hosts: all
  connection: local
  tasks:
    - name: ssh-keyscan
      command: "ssh-keyscan {{ ansible_host|default(inventory_hostname)}}"
      register: out

 

Often, run_once: true is used so that the task is only ran one time on the control node.

---
- hosts: all
  connection: local
  tasks:
    - name: ssh-keyscan
      command: "ssh-keyscan {{ ansible_host|default(inventory_hostname)}}"
      run_once: true
      register: out

 


Roles

All of the tasks in a particular role can be performed on the control node. In this example, every task in the "foo" role will be performed on the control node.

Or like this.

---
- hosts: all
  roles:
    - role: foo
      connection: local

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter ac519 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |