



+ $Host = invoke-command -computer $comp -Scriptblock -Cred. + FullyQualifiedErrorId : CannotUseIPAddress,PSSessionStateBrokenĬannot overwrite variable Host because it is read-only or constant. + CategoryInfo : OpenError: (34.160.160.130:String), PSRemotingTransportException For more information, see the about_Remote_Troubleshooting Help topic. For more information on how to set TrustedHosts run the following command: winrm helpĬonfig. Note that computers in the TrustedHosts list might not be authenticated. With an IP address under the following conditions: the transport is HTTPS or the destination is in the TrustedHosts list, and explicit credentials are provided. Connecting to remote server 34.160.160.130 failed with the following error message : The WinRM client cannot process the request. $Cred = New-Object (“username”, $password) If you refer this post and look at the Facts being collected you would be able to understand where this information is coming from.Īlso, this is the IP being used to ansible master to connect to the target, so this can be used as the Righteous IP in all requirements.Įxecution Output $ ansible-playbook GetIPHosts.$password = ConvertTo-SecureString “PlainTextPassword” -AsPlainText -Force Gather_facts: yes tasks: - debug: var=hostvars.SSH_CONNECTION.split( ' ') The following playbook would show how to get the IP address of the remote target or host using the SSH Connection between the ansible master and the host. To know more about Ansible Gather_facts and to see what facts are being collected. If you know already, ansible Gather_facts collects all the information about the remote hosts and it provides a various lot of information about the remote host including the IP address being used for SSH connection. to get the remote IP address with ansible we are relying on the SSH connectivity between the Ansible Master and remote host(target) The /etc/hosts update post tagged above has also implemented with this method. This is the method I have been using for a while and It never failed me. Sometimes, we would use the public IP to connect to the remote host in such cases we would want to use this method.ĪWS hosts are the best example for this type as this method would use the public IP or the domain_name we have used to connect to the EC2 instance. In this method, we are going to use the IP address used by Ansible master to connect to the Remote Host. Method1: Get the IP used by Ansible master to connect
