I have a simple ansible role and couple of basic tasks within this role. All tasks are defined as local_action
(or delegate_to: localhost
). The host defined in the playbook is also localhost
.
Now when I am running this playbook, it first tries to test ssh connection before executing the role/tasks. This is not a problem but I find it unnecessary to establish or test ssh connection before running a playbook which is explicitly targeting localhost
as host. Following is how my playbook (playbook.yml
) looks like:
- hosts: db-servers
roles:
- role: test
And the role definition (roles/test/tasks/main.yml
) looks as follow:
---
- name: Resolve and copy test configuration
template:
src: "roles/test/templates/temp.conf"
dest: "roles/test/files/temp-4.2.0/temp.conf"
delegate_to: 127.0.0.1
become: no
- name: Run test job
delegate_to: 127.0.0.1
command: roles/test/files/test-4.2.0/test.sh
become: no
Following is my inventory file inv/test
:
[db-servers]
localhost
And I am using this command to run my playbook:
ansible-playbook -i inv/test playbook.yml -vvv
Is there anyway in ansible that I could prevent this ssh connectivity check?
Add connection: local
as a task property.
- name: Run test job
delegate_to: 127.0.0.1
connection: local
command: roles/test/files/test-4.2.0/test.sh
become: no
Or define the host in the inventory and assign the connection type:
127.0.0.1 ansible_connection=local
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With