local_action tries to ssh to localhost

1,062 views
Skip to first unread message

raji sankaran

unread,
Oct 26, 2017, 4:49:39 PM10/26/17
to Ansible Project
I have the following task as part of a playbook which needs to be run on localhost. This tasks is for checking if the ansible host is able to ssh to remote server.

- name: Verify-User
  local_action
: shell ssh -o PreferredAuthentications=publickey -o StrictHostKeyChecking=no -i {{ role_path }}/files/authorized_keys.ansible -o ConnectTimeout=10 {{ createuser }}@{{ node }} "echo success"
 
register: user_enabled
  ignore_errors
: yes



This task is called from a playbook using the following command. I need the extra vars to connect to server if ssh fails and create a new ansible user.

ansible
-playbook -i "1.0.0.0," setup-host.yml --extra-vars "node=1.0.0.0, ansible_connection=ssh ansible_ssh_user=root ansible_ssh_pass=test"



Running the playbook gives,

hosts": {

                        "1.0.0.0": {

                            "changed": false, 

                            "msg": "Failed to connect to the host via ssh: ssh: connect to host localhost port 22: Connection refused\r\n", 

                            "unreachable": true

                        }

                    }


If i remove ansible_connection=ssh from the command, this gives a different error, but atleast it wasnt trying to ssh. 

My question is 
 -  why is local_action trying to ssh? If its due to ansible_connection=ssh, is there a way this can be overriden for a specific task? "connection: local" dint work.
 -  Shouldnt the hosts for this tasks say "localhost" ? Why is it showing the hosts as the ip of remote server. Does this mean local_action did not take effect?

Thanks.

Brian Coca

unread,
Oct 27, 2017, 11:35:58 AM10/27/17
to Ansible Project
This is precedence issue, caused by extra var ansible_connection=ssh,
'local_action' is the same as 'delegate_to: localhost', but the extra
var setting is overriding localhosts normal 'connection=local'





--
----------
Brian Coca

raji sankaran

unread,
Oct 27, 2017, 11:44:58 AM10/27/17
to Ansible Project
Thanks. I was curious, Is there a way to override the extra vars on a specific task? I want just one task to have connection: local.

Brian Coca

unread,
Oct 27, 2017, 11:52:59 AM10/27/17
to Ansible Project
no, extra_vars have the highest precedence, they are really the 'big hammer'




--
----------
Brian Coca

raji sankaran

unread,
Oct 27, 2017, 3:22:09 PM10/27/17
to Ansible Project
Thanks, Brian
Reply all
Reply to author
Forward
0 new messages