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 2,660 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,460 points
i have created [appserver] in /etc/ansible/hosts file. But even i updated in my playbook

hosts: appserver

after i run my playbook, but get same error

TASK [To Run Commands to shutdown server with schedule] ************************
fatal: [P-address]: FAILED! => {"changed": false, "elapsed": 0, "msg": "Running win_reboot with local connection would reboot the control node.", "rebooted": false}

Below is my playbook

---
- name: To Start EC2  instances
  hosts: appserver
  gather_facts: false
  connection: local
  vars:
#instance_ids:
#region:
  tasks:
    - name: Start the feature instances
      ec2:
        instance_ids: '{{ instance_ids }}'
        region: '{{ region }}'
        state: running
        wait: true
    - name: To Run a Shell Script
      script: /home/Describe-AD-Server.sh > AD-Server-Describe
    - name: To Run Commands to shutdown server with schedule
      win_reboot:
       shutdown_timeout: 600

can you check my code?
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.

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
15,650 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
14,656 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,413 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,890 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
4,016 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,460 points
2,029 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