awesome. Thanks.
so is there a way to have my inventory file in its own separate text file.?
I have it all in the vars.yml file now?
deploy_env:
instance_type: t2.micro
image: ami-02d03ce209db75523
sg_group:
- "sg-057771872265bfda6"
region: us-west-1
vpc_subnet_id: subnet-0d9d37440a2265163
instance_tags:
date: 1.20.2022
instances:
- name: test1
ip: 10.10.1.10
- name: test2
ip: 10.10.1.11
On Tue, Feb 8, 2022 at 7:11 AM Dick Visser <[email protected]> wrote:
> yes
>
> You loop over the ec2_instance task.
> So, you will also need to loop over the result.
>
> I think this should work:
>
> - name: wait for instance creation to complete
> async_status:
> jid: "{{ item.ansible_job_id }}"
> register: ec2_jobs
> until: ec2_jobs.finished
> retries: 300
> loop: "{{ ec2.results }}"
>
>
>
> On Tue, 8 Feb 2022 at 16:05, Tony Wong <[email protected]> wrote:
>
>> hi,
>>
>> any idea why I keep getting this error when i run this asyn job?
>>
>> fatal: [localhost]: FAILED! => {
>> "ansible_job_id": "ec2.ansible_job_id",
>> "attempts": 1,
>> "changed": false,
>> "finished": 1,
>> "invocation": {
>> "module_args": {
>> "_async_dir": "/Users/tonywong/.ansible_async",
>> "jid": "ec2.ansible_job_id",
>> "mode": "status"
>> }
>> },
>> "msg": "could not find job",
>> "started": 1
>> }
>>
>>
>>
>> ---------------------------------------------------------------------------
>>
>> ---
>> - include_vars: vars/main.yml
>> - name: create the ec2 instance
>> ec2:
>> assign_public_ip: no
>> group_id: '{{ deploy_env.sg_group }}'
>> instance_type: "{{ deploy_env.instance_type }}"
>> image: "{{ deploy_env.image }}"
>> wait: yes
>> wait_timeout: 600
>> count: 1
>> region: "{{ deploy_env.region }}"
>> vpc_subnet_id: "{{ deploy_env.vpc_subnet_id}}"
>> private_ip: "{{ item.ip }}"
>> register: ec2
>> with_items: "{{ instances }}"
>> loop: "{{ instances }}"
>> async: 60
>> poll: 0
>>
>> - name: wait for instance creation to complete
>> async_status:
>> jid: ec2.ansible_job_id
>> register: ec2_jobs
>> until: ec2_jobs.finished
>> retries: 300
>>
>> On Tue, Jan 25, 2022 at 9:45 AM Tony Wong <[email protected]> wrote:
>>
>>>
>>> Thank you. This works great.
>>> On Monday, January 24, 2022 at 12:51:24 AM UTC-8 [email protected]
>>> wrote:
>>>
>>>> Hii
>>>>
>>>>
>>>> On Sun, 23 Jan 2022 at 16:01, Tony Wong <[email protected]> wrote:
>>>> >
>>>> > I am just trying to create 2 or more ec2 instances.
>>>>
>>>> Here you say 2
>>>>
>>>>
>>>> >>> - name: create the ec2 instance
>>>> >>> ec2:
>>>> >>> assign_public_ip: no
>>>> >>> group_id: '{{ deploy_env.sg_group }}'
>>>> >>> instance_type: "{{ deploy_env.instance_type }}"
>>>> >>> image: "{{ deploy_env.image }}"
>>>> >>> wait: true
>>>> >>> wait_timeout: 600
>>>> >>> count: 10
>>>>
>>>> But here it says 10 are created.
>>>>
>>>> https://docs.ansible.com/ansible/latest/collections/amazon/aws/ec2_module.html#parameter-count
>>>>
>>>> Assuming this is an oversight, this should work:
>>>>
>>>> - include_vars: vars/main.yml
>>>>
>>>> - name: create the ec2 instance
>>>>
>>>> ec2:
>>>>
>>>> assign_public_ip: no
>>>>
>>>> group_id: '{{ deploy_env.sg_group }}'
>>>>
>>>> instance_type: "{{ deploy_env.instance_type }}"
>>>>
>>>> image: "{{ deploy_env.image }}"
>>>>
>>>> wait: true
>>>>
>>>> wait_timeout: 600
>>>>
>>>> count: 1
>>>>
>>>> region: "{{ deploy_env.region }}"
>>>>
>>>> vpc_subnet_id: "{{ deploy_env.vpc_subnet_id}}"
>>>>
>>>> private_ip: "{{ item.ip }}"
>>>>
>>>> instance_tags:
>>>>
>>>> Name: "{{ item.name }}"
>>>>
>>>> loop: "{{ instances }}"
>>>>
>>>>
>>>>
>>>> And then in your vars file:
>>>>
>>>> deploy_env:
>>>>
>>>> instance_type: t2.micro
>>>>
>>>> image: ami-02d03ce209db75523
>>>>
>>>> sg_group:
>>>>
>>>> - "sg-057771872265bfda6"
>>>>
>>>> region: us-west-1
>>>>
>>>> vpc_subnet_id: subnet-0d9d37440a2265163
>>>>
>>>>
>>>>
>>>> instances:
>>>>
>>>> - name: test1
>>>>
>>>> ip: 10.10.1.10
>>>>
>>>> - name: test2
>>>>
>>>> ip: 10.10.1.12
>>>>
>>>> - name: test43
>>>>
>>>> ip: 10.10.1.77
>>>>
>>>>
>>>>
>>>> --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "Ansible Project" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/ansible-project/fsQdjZ1Ica8/unsubscribe
>>> .
>>> To unsubscribe from this group and all its topics, send an email to
>>> [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/3bbfe10d-61a4-4994-902f-56e117e218afn%40googlegroups.com
>>> <https://groups.google.com/d/msgid/ansible-project/3bbfe10d-61a4-4994-902f-56e117e218afn%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/CALmkhkroS%2BrO8yCizkvXCjF3XFACJyz%2BaW%3DNMRzjg2ZsEC%3DtfQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/ansible-project/CALmkhkroS%2BrO8yCizkvXCjF3XFACJyz%2BaW%3DNMRzjg2ZsEC%3DtfQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> --
> Dick Visser
> Trust & Identity Service Operations Manager
> GÉANT
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ansible-project/fsQdjZ1Ica8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAL8fbwN77uuQSCHOtWmXfKCaXEVvFMudN%2BrDJgrx5S%3DdvwJ32Q%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAL8fbwN77uuQSCHOtWmXfKCaXEVvFMudN%2BrDJgrx5S%3DdvwJ32Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CALmkhkr6cVXiiFbQHG0vEZLyiC1ikL%2BhmNBOmmHN3BrPPreV9Q%40mail.gmail.com.