Is it possible to start ec2 Windows machine and run windows command using ansible playbook

0 votes
Is it possible to start ec2 windows instance and run windows command after started the same ec2 instance using the same ansible-playbook from local system? Because VM taking some time to start... So how is possible with two tasks in the same playbook?
Aug 14, 2020 in Ansible by Lakshminarayanan
• 1,370 points

edited Aug 14, 2020 by MD 1,990 views

1 answer to this question.

0 votes

Hi@Lakshminarayanan,

Yes, you can do that. But after you launched your ec2 instance, you have to update your Ansible inventory file in the below format.

$ ec2-instance ansible_host=<<ec2-instance-ip>> ansible_user=ec2-user ansible_ssh_private_key_file=/location/of/the/keypair/your-key.pem

After that, you can run any command inside your EC2 instance.

name: Run any command
hosts: ec2-instance
become: yes
become_user: root
tasks: {{ write your commands }}
answered Aug 14, 2020 by MD
• 95,440 points
Everything seems ok in your playbook. Which protocol you are using to login to your remote windows system?
you mean should i do some thing like configuration in windows machine? Because its RDP. Its confusing bro. I can start and stop the remote windows instance whereas i cant do with windows commands. I didn't any special configuration before connect remote windows instance. Where im wrong.

Yes, I think so. Because if it is a Linux system then it can be done through SSH protocol. But it is a Windows system and it does not work on SSH by default. So as you are using RDB protocol, some configurations require. You can start and stop your instance because you don't have to login inside your instance to do that. But to run any command in your instance, you need to login to your instance.

uderstood bro. Can you tell me the steps to achieve this. Because im not aware about this.

Hi@Lakshminarayanan,

You can check the below blog. It has the steps to configure the Windows system as a managed node.

https://www.linuxtechi.com/manage-windows-host-using-ansible/

Related Questions In Ansible

0 votes
1 answer

Is it possible to run an Ansible Playbook in python script?

Hey @Cerci, Of course its possible. You ...READ MORE

answered Jan 17, 2019 in Ansible by Nicolas
14,995 views
+1 vote
1 answer

Is it possible to append a large amount of text to a file using Ansible?

Here is concept which you can follow. blockinfile is ...READ MORE

answered Jul 30, 2018 in Ansible by Atul
• 10,240 points
13,992 views
0 votes
1 answer

Is it possible to run commands on ansible host?

If you just trying to run a ...READ MORE

answered Jan 10, 2019 in Ansible by Vijay
1,227 views
0 votes
1 answer

Is it possible to run a playbook with a crontab?

Ofcourse you can run ansible playbook with ...READ MORE

answered Jan 17, 2019 in Ansible by Yesha
4,540 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,459 views
+2 votes
1 answer
0 votes
1 answer

How to launch an EC2 instance using Ansible Playbook?

Hi@akhtar, Ansible has one module named ec2. This ...READ MORE

answered Aug 12, 2020 in Ansible by MD
• 95,440 points
1,707 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP