简体   繁体   中英

How to connect to a Windows EC2 instance using Ansible?

From reading the Connect to your Windows instance AWS EC2 docs page, my understanding is that it is not possible to SSH to Windows EC2 instances.

The typical procedure to connect to a Windows EC2 instance manually is to download the remote desktop file, get the password for the instance, and then use the Remote Desktop Connection tool to RDP to the instance (more detail is in the docs page above).

If I am correct that Windows EC2 instances do not support connecting via SSH, how can you connect to a Windows EC2 in an Ansible playbook?

I would prefer to be able to do this without installing any software on the Windows EC2 instance beforehand, but if that is necessary, I can do that.

I have found you need to do the following to connect to a Windows EC2 instance using Ansible:

  • You need to configure the EC2 to allow connections from Ansible using the ConfigureRemotingForAnsible.ps1 script . This can be done either by setting this as the user data when you create the EC2, or by running this script after the EC2 is created.
  • You need add a security group, or configure a security group already added to the EC2 to allow the following incoming requests to the EC2 from the host(s) that the Ansible playbook will be running on:
    • WinRM
    • TCP requests to whatever you configure as the Ansible port
  • You need to install pywinrm>=0.3.0 so Ansible can use WinRM to connect to the EC2.
  • You need to run the Ansible playbook with ansible_connection variable set to winrm , and the ansible_winrm_scheme variable set to http . This can be done with --extra-args or any other way that variables are set.
  • You need to provide the public IP address of the Windows EC2 host, either under hosts in the playbook, or in a host file passed to ansible-playbook with -i .
  • You need to get or set the EC2's Administrator password, and then provide this password with the ansible_password variable for the EC2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM