Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible delegate_to task trying to ssh

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?

like image 742
Obaid Maroof Avatar asked Mar 08 '23 15:03

Obaid Maroof


1 Answers

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
like image 172
techraf Avatar answered May 16 '23 10:05

techraf