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.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/60e905cd-1161-4212-b573-f89acd59cd23%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to