I'm planning to get some of these roles onto Galaxy, but until then...
The next tasks in that particular play are:
- name: wait for instances to listen on port 5986 (winrm https)
wait_for:
state=started
host={{ item.tagged_instances[0].public_ip }}
port=5986
with_items: win_ec2.results
when: win_ec2_images and win_ec2 is defined
- name: obtain windows passwords for instances
ec2_win_pass:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
region: '{{ win_ec2_region }}'
instance_id: "{{ item.tagged_instances[0].id }}"
private_key: "{{ lookup('file', win_ec2_private_key) }}"
with_items: win_ec2.results
register: win_ec2_passwords
when: win_ec2_images and win_ec2 is defined
- name: add_host
add_host:
name: '{{ item.item.tagged_instances[0].public_dns_name }}'
groups: 'cloud,ec2,windows,{{win_ec2_name_prefix}}-{{
item.item.item.name }}'
ansible_ssh_host: '{{ item.item.tagged_instances[0].public_ip }}'
ansible_ssh_port: 5986
ansible_ssh_user: '{{ item.item.item.user }}'
ansible_ssh_pass: '{{ item.password }}'
ansible_connection: 'winrm'
with_items: win_ec2_passwords.results
when: win_ec2_images and win_ec2_passwords is defined
The second task is using my module from
https://github.com/ansible/ansible-modules-core/pull/378
You can also save these new hosts to an inventory file (using template
module).
After the play above runs, I can then run another play to ping the
newly-launched Windows hosts:
- name: ping new windows instances
hosts: windows
gather_facts: false
tasks:
- action: win_ping
Hope that helps!
On Thu, Dec 18, 2014 at 12:46 AM, Rob White <[email protected]> wrote:
>
> Hi Chris,
>
> What's your approach for logging in to your Win boxes using WinRM after
> this step?
>
> Ansible docs direct you to configure a vars file with ansible_ssh_pass set
> however every ec2 instance is going to have a different password. I've
> created a module for using boto to get the ec2 password but i dont know how
> to chain this through to then use it for a following play which would
> configure my windows instances.
>
>
> On Sunday, 26 October 2014 06:33:32 UTC+11, Chris Church wrote:
>>
>> The file lookup plugin is your friend.
>>
>> I'm using the following task for launching Windows instances and
>> configuring PowerShell remoting:
>>
>> - ec2:
>> aws_access_key: '{{ aws_access_key }}'
>> aws_secret_key: '{{ aws_secret_key }}'
>> region: '{{ win_ec2_region }}'
>> instance_type: '{{ win_ec2_instance_type }}'
>> instance_tags:
>> Name: '{{win_ec2_name_prefix}}-{{item.name}}'
>> group: '{{ win_ec2_security_group }}'
>> key_name: '{{ win_ec2_key_name }}'
>> image: '{{ item.id }}'
>> user_data: "{{ lookup('file', 'win_ec2_user_data') }}"
>> exact_count: 1
>> count_tag:
>> Name: '{{win_ec2_name_prefix}}-{{item.name}}'
>> wait: yes
>> with_items: win_ec2_images
>> register: win_ec2
>>
>>
>> My win_ec2_user_data file contains:
>>
>> <powershell>
>> iex ((new-object net.webclient).DownloadString('https://raw.
>> githubusercontent.com/ansible/ansible/devel/examples/scripts/
>> ConfigureRemotingForAnsible.ps1'))
>> </powershell>
>>
>>
>>
>>
>> On Fri, Oct 24, 2014 at 8:00 PM, Michael DeHaan <[email protected]>
>> wrote:
>>
>>> I don't believe YAML takes Python-like docstrings.
>>>
>>> So you would need to start with a single or double quote and escape any
>>> internal quotes as need be.
>>>
>>> The "file" lookup plugin may also be helpful.
>>>
>>> On Fri, Oct 24, 2014 at 12:06 PM, Erick Barros <[email protected]>
>>> wrote:
>>>
>>>> I got the following error:
>>>>
>>>> ERROR: Syntax Error while loading YAML script, /etc/ansible/playbooks/
>>>> search/roles/aws/tasks/main.yml
>>>> Note: The error may actually appear before this position: line 13,
>>>> column 17
>>>>
>>>>
>>>> state: running
>>>> user_data: """#!/bin/bash
>>>> ^
>>>> This one looks easy to fix. It seems that there is a value started
>>>> with a quote, and the YAML parser is expecting to see the line ended
>>>> with the same kind of quote. For instance:
>>>>
>>>>
>>>> when: "ok" in result.stdout
>>>>
>>>>
>>>> Could be written as:
>>>>
>>>>
>>>> when: '"ok" in result.stdout'
>>>>
>>>>
>>>> or equivalently:
>>>>
>>>>
>>>> when: "'ok' in result.stdout"
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Saturday, August 16, 2014 12:04:59 PM UTC-3, Michael DeHaan wrote:
>>>>>
>>>>> (a) can you please show the line from your playbook where you are
>>>>> using the user data variable?
>>>>>
>>>>> (b) with the above, how are you determining the way it fails? I.e.
>>>>> what does failure look like?
>>>>>
>>>>>
>>>>> On Fri, Aug 15, 2014 at 5:36 PM, Jonathan Nakatsui <[email protected]>
>>>>> wrote:
>>>>>
>>>>>> From the ansible docs the ec2 module (http://docs.ansible.com/ec2_m
>>>>>> odule.html) mentions a user_data field. However, there is no example
>>>>>> showing the use of user_data.
>>>>>>
>>>>>> I've tried a variety of things to pass through to the user field to
>>>>>> no avail including
>>>>>>
>>>>>> user_data: file.txt
>>>>>>
>>>>>> user_data: "{{ lookup('file', file.txt') }}"
>>>>>>
>>>>>> user_data: """#!/bin/bash
>>>>>> apt-get update
>>>>>> apt-get install htop"""
>>>>>>
>>>>>> And variations thereof. My googlefu has failed me so far to find any
>>>>>> results for how to solve this issue.
>>>>>>
>>>>>> Thanks if you have any input.
>>>>>>
>>>>>> --
>>>>>> 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 post to this group, send email to [email protected].
>>>>>> To view this discussion on the web visit https://groups.google.com/d/
>>>>>> msgid/ansible-project/64b86c47-036a-471f-8a64-9cbd38c04f5c%
>>>>>> 40googlegroups.com
>>>>>> <https://groups.google.com/d/msgid/ansible-project/64b86c47-036a-471f-8a64-9cbd38c04f5c%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>>
>>>>> --
>>>> 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 post to this group, send email to [email protected].
>>>> To view this discussion on the web visit https://groups.google.com/d/
>>>> msgid/ansible-project/a1c6540e-6ece-49b8-84f8-
>>>> 83802cb97ebb%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/ansible-project/a1c6540e-6ece-49b8-84f8-83802cb97ebb%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>> --
>>> 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 post to this group, send email to [email protected].
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/ansible-project/CA%2BnsWgyG79kBFTw3O_i62_
>>> FTd7MeBtuvLWUNnEauFLfNkQw66w%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgyG79kBFTw3O_i62_FTd7MeBtuvLWUNnEauFLfNkQw66w%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> 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 post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/3960ea12-56fa-4ee1-a902-6c090ea72ae0%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/3960ea12-56fa-4ee1-a902-6c090ea72ae0%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
--
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAH%2BKTJ7yGCO1RqPsSjXCLUvpSc8gktddwsY7E1rmJMYK-P9Tkw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.