Hi Juerg, I tried your example too. It also works in version 2.10.6.
I think for my use case it is the best way to add the remote host during the play with add_host. Thank you! Happy weekend and best regards, Raphael Juerg Ritter schrieb am Freitag, 26. Februar 2021 um 22:13:48 UTC+1: > Hi Raphael, > > Happy to hear you got it working! I just played around a bit more, and > apparently, there is a way even without adding your host to the inventory. > Here an example, which I ran on Ansible 2.9.17: > > - name: Remote Port Test > hosts: localhost > tasks: > - name: delegate command > command: whoami > delegate_to: rhel8 > vars: > ansible_ssh_port: 2222 > > That said, I still think it is in general a good idea to add all the hosts > which the playbook interacts with to the inventory and configure all the > connection parameters there. You may wanna use delegate_to in combination > with connection plugins other than SSH (e.g. WinRM), which require > different configuration parameters. > > Happy weekend and best regards, > Juerg > > On Fri, Feb 26, 2021 at 5:38 PM Raphael Ebner <[email protected]> > wrote: > >> Hi Juerg >> >> thank you very much, it is working fine with add_host :) >> >> Is that worth a feature request, to use remote_port (similar naming to >> remote_user) together with delegate_to? >> >> Best Regards, >> Raphael >> >> Juerg Ritter schrieb am Donnerstag, 25. Februar 2021 um 22:23:15 UTC+1: >> >>> Hi Raphael, >>> >>> Oh I see. One solution might be to use the add_host module, which allows >>> you to add hosts to your inventory on the fly (it won't be persisted). Just >>> add a task which adds your target host for the delegation along with the >>> ansible_port variable before your delegate_to task. >>> >>> The documentation can be found here: >>> >>> https://docs.ansible.com/ansible/latest/collections/ansible/builtin/add_host_module.html >>> >>> Hope this helps! >>> -- Juerg >>> >>> >>> >>> On Thu, Feb 25, 2021 at 10:13 PM Raphael Ebner <[email protected]> >>> wrote: >>> >>>> Hi Juerg, >>>> >>>> Yes, the host is part of my Inventory. >>>> I tried it and set delegate_to to the inventory hostname, which woks >>>> fine. >>>> >>>> But I've multiple inventories, and all hosts of each inventory needs >>>> this delegated_to task. How can I handle it for all other inventories, >>>> because I can't add this host to all inventories? >>>> Have you an idea? >>>> >>>> Regards, >>>> Raphael >>>> >>>> Juerg Ritter schrieb am Donnerstag, 25. Februar 2021 um 21:46:25 UTC+1: >>>> >>>>> Hi Raphael, >>>>> >>>>> Is the host you are trying to delegate the task to part of your >>>>> inventory? >>>>> >>>>> My next try would be to add this host in the inventory and specify the >>>>> custom port for this particular host as a host variable. An example can >>>>> be >>>>> found here: >>>>> >>>>> https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#assigning-a-variable-to-one-machine-host-variables >>>>> >>>>> I hope that helps! >>>>> >>>>> Regards, Juerg >>>>> >>>>> On Thu, Feb 25, 2021 at 9:30 PM Raphael Ebner < >>>>> [email protected]> wrote: >>>>> >>>>>> Hi Community, >>>>>> >>>>>> I need to delegate one task in my play to another remote linux ssh >>>>>> host with delegate_to. So far so good. But now the problem: my remote >>>>>> host >>>>>> has a custom ssh port. When running the play I always get "Failed to >>>>>> connect to the host via ssh: ssh: connect to host x.x.x.x port 22: >>>>>> Connection timed out". How can I specify at task level a custom ssh port >>>>>> for delegate_to? >>>>>> >>>>>> I already tried: "delegate_to: IP:PORT" and setting "ansible_port: >>>>>> PORT" at task level, but without success. >>>>>> >>>>>> May someone has an idea how to handle this problem? >>>>>> >>>>>> Regards, >>>>>> Raphael >>>>>> >>>>>> -- >>>>>> 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 view this discussion on the web visit >>>>>> https://groups.google.com/d/msgid/ansible-project/fbd59df7-f298-4f7a-90a0-64b7f94f8a24n%40googlegroups.com >>>>>> >>>>>> <https://groups.google.com/d/msgid/ansible-project/fbd59df7-f298-4f7a-90a0-64b7f94f8a24n%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>>> . >>>>>> >>>>> >>>>> >>>>> -- >>>>> >>>>> Jürg Ritter, RHCE >>>>> Consultant >>>>> >>>>> Red Hat Switzerland <https://www.redhat.com/> >>>>> >>>>> Europaallee 41 >>>>> >>>>> CH-8021 Zürich >>>>> >>>>> [email protected] >>>>> M: +41-(0)79-715-09-90 <+41%2079%20715%2009%2090> >>>>> <https://www.redhat.com/> >>>>> >>>> -- >>>> 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 view this discussion on the web visit >>>> https://groups.google.com/d/msgid/ansible-project/9a431557-346e-4c81-b4db-ae0e932e1dccn%40googlegroups.com >>>> >>>> <https://groups.google.com/d/msgid/ansible-project/9a431557-346e-4c81-b4db-ae0e932e1dccn%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>> >>> >>> -- >>> >>> Jürg Ritter, RHCE >>> Consultant >>> >>> Red Hat Switzerland <https://www.redhat.com/> >>> >>> Europaallee 41 >>> >>> CH-8021 Zürich >>> >>> [email protected] >>> M: +41-(0)79-715-09-90 <+41%2079%20715%2009%2090> >>> <https://www.redhat.com/> >>> >> -- >> 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 view this discussion on the web visit >> https://groups.google.com/d/msgid/ansible-project/50d8ee7d-b602-4bcd-986c-445951a154can%40googlegroups.com >> >> <https://groups.google.com/d/msgid/ansible-project/50d8ee7d-b602-4bcd-986c-445951a154can%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > > > -- > > Jürg Ritter, RHCE > Consultant > > Red Hat Switzerland <https://www.redhat.com/> > > Europaallee 41 > > CH-8021 Zürich > > [email protected] > M: +41-(0)79-715-09-90 <+41%2079%20715%2009%2090> > <https://www.redhat.com/> > -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/23f306ed-063d-44ed-9bf1-d14259277f3cn%40googlegroups.com.
