Search code examples
ansiblesusesles

Ansible using delegate_to with different ansible_ssh_common_args


I'm trying to make a run from my ansible master to a host (lets call it hostclient) which requires performing something into another host (let's call it susemanagerhost :) ).

hostclient needs ansible_ssh_common_args with proxycommand fullfilled, while susemanager host needs no ansible_ssh_common_args since its a direct connection.

So I thought I could use delegate_to, but the host called hostclient and the host called susemanagerhost have different values for the variable ansible_ssh_common_args.

I thought I could change the value of ansible_ssh_common_args inside the run with set_fact of ansible_ssh_common_args to ansible_ssh_common_args_backup (because I want to recover the original value for the other standard tasks) and then ansible_ssh_common_args to null (the connection from the ansible master to susemanager host is a direct connection with no proxycommand required) but it is not working.
It seems like its still using the original value for ansible_ssh_common_args.


Solution

  • ansible_ssh_common_args is generally used to execute commands 'through' a proxy server:

    <ansible system> => <proxy system> => <intended host>
    

    The way you formulated your question you won't need to use ansible_ssh_common_args and can stick to using delegate_to:

    - name: execute on host client
      shell: ls -la
    
    - name: execute on susemanagerhost
      shell: ls -la
      delegate_to: "root@susemanagerhost"
    

    Call this play with:

    ansible-playbook <play> --limit=hostclient
    

    This should do it.

    Edit: After filing a bug on github the working solution is to have:

    ansible_ssh_common_args: '-o StrictHostKeyChecking=no -o ProxyCommand="ssh -W %h:%p -i ~/.ssh/id_rsa ansible@{{ jumphost_server }}"'
    

    In host_vars or group_vars. Followed by a static use of delegate_to:

    delegate_to: <hostname>
    

    hostname should be the hostname as used by ansible.

    But not use:

    delegate_to: "username@hostname"
    

    This resolved the issue for me, hope it works out for you as well.