Re: [ansible-project] Block & rescue misconception

2019-01-29 Thread Sergio Fernandez
Hi all,

For the record, as I think this is not specifically documented in the
official documentation:

When using block inside a role, the correct syntax is:
---

- block:
  - name: Do stuff
[...]
tags:
  - tag
  - othertag
  - name: Do more stuff
[...]
tags:
  - tag
  - othertag
[...]
  rescue:
- name: Do some recevery stuff
  [...]
  tags:
- tag
- rescue
- name: Do more recovery stuff
  [...]
  tags:
- tag
- rescue

I've managed to do my stuff.

*Sergio Fernández*
SysAdmin and DevOps Engineer

*exoinvesting.com *

Email: *sergio.fernan...@exoinvesting.com
*
Phone:
*+34 679 51 25 22*
Follow me on *LinkedIn
*

Exo Investing Limited, trading under the name Exo Investing, is authorised
& regulated by the Financial Conduct Authority (FRN: 748161). Exo
Investing Limited
(formerly Finhub Technologies Limited)  is registered in England & Wales
with company number 10094765 and its registered office address at Spaces,
Citypoint, 1 Ropemaker St, London, EC2Y 9HT.

Confidentiality Notice: This e-mail message, including any attachments,
sent on behalf of Exo Investing Limited is for the sole use of the intended
recipient(s) and may contain confidential and privileged information. Any
unauthorized review, use, copying, disclosure or distribution is
prohibited. If you are not the intended recipient, please contact the
sender by reply e-mail and destroy all copies of the original message.
Thank you.


On Tue, 29 Jan 2019 at 12:51, Sergio Fernandez <
sergio.fernan...@exoinvesting.com> wrote:

> HI,
>
> Si as far as I understand, and my tests points to int, a block & rescue is
> needed for every task in a role? Is not applicable to various tasks?
>
> Regards.
> *Sergio Fernández*
> SysAdmin and DevOps Engineer
>
> *exoinvesting.com *
>
> Email: *sergio.fernan...@exoinvesting.com
> *
> Phone:
> *+34 679 51 25 22*
> Follow me on *LinkedIn
> *
>
> Exo Investing Limited, trading under the name Exo Investing, is authorised
> & regulated by the Financial Conduct Authority (FRN: 748161). Exo Investing
> Limited (formerly Finhub Technologies Limited)  is registered in England
> & Wales with company number 10094765 and its registered office address at
> Spaces, Citypoint, 1 Ropemaker St, London, EC2Y 9HT.
>
> Confidentiality Notice: This e-mail message, including any attachments,
> sent on behalf of Exo Investing Limited is for the sole use of the
> intended recipient(s) and may contain confidential and privileged
> information. Any unauthorized review, use, copying, disclosure or
> distribution is prohibited. If you are not the intended recipient, please
> contact the sender by reply e-mail and destroy all copies of the original
> message. Thank you.
>
>
> On Mon, 28 Jan 2019 at 18:19, Kai Stian Olstad <
> ansible-project+l...@olstad.com> wrote:
>
>> On 28.01.2019 17:52, sergio.fernan...@exoinvesting.com wrote:
>> > instance). But I don't know why the rescue tasks never runs.
>> >
>> > And the role deploy-api/tasks/main.yml looks like this:
>> >
>> > ---
>> > - block:
>> >   - name: Create .ssh path for user
>> > become: yes
>> > file:
>> >path: "{{ deploy_path }}/.ssh"
>> >owner: example
>> >group: example
>> >state: directory
>> >mode: 0700
>> > tags:
>> >   - backend
>> >   - ssh
>> >
>> >   - name: Upload RSA public key
>> > become: yes
>> > template:
>> >   src: 'templates/example-id_rsa.pub'
>> >   dest: "{{ deploy_path }}/.ssh/authorized_keys"
>> >   owner: example
>> >   group: example
>> >   mode: 0640
>> > tags:
>> >   - backend
>> >   - ssh
>> > [ ...More stuff... ]
>> >
>> > - rescue:
>>
>> Your syntax is wrong, rescue should not have a dash, check the
>> documentation for correct syntax
>> https://docs.ansible.com/ansible/latest/user_guide/playbooks_blocks.html
>>
>> --
>> Kai Stian Olstad
>>
>> --
>> 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/2s3HSs_Ke_4/unsubscribe
>> .
>> To unsubscribe from this group and all its topics, send an email to
>> ansible-project+unsubscr...@googlegroups.com.
>> To post to this group, send email to ansible-project@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/1e5e34a35809bb5b7cd8824e01f54b80%40olstad.com
>> .
>> 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 

Re: [ansible-project] Block & rescue misconception

2019-01-29 Thread Sergio Fernandez
HI,

Si as far as I understand, and my tests points to int, a block & rescue is
needed for every task in a role? Is not applicable to various tasks?

Regards.
*Sergio Fernández*
SysAdmin and DevOps Engineer

*exoinvesting.com *

Email: *sergio.fernan...@exoinvesting.com
*
Phone:
*+34 679 51 25 22*
Follow me on *LinkedIn
*

Exo Investing Limited, trading under the name Exo Investing, is authorised
& regulated by the Financial Conduct Authority (FRN: 748161). Exo
Investing Limited
(formerly Finhub Technologies Limited)  is registered in England & Wales
with company number 10094765 and its registered office address at Spaces,
Citypoint, 1 Ropemaker St, London, EC2Y 9HT.

Confidentiality Notice: This e-mail message, including any attachments,
sent on behalf of Exo Investing Limited is for the sole use of the intended
recipient(s) and may contain confidential and privileged information. Any
unauthorized review, use, copying, disclosure or distribution is
prohibited. If you are not the intended recipient, please contact the
sender by reply e-mail and destroy all copies of the original message.
Thank you.


On Mon, 28 Jan 2019 at 18:19, Kai Stian Olstad <
ansible-project+l...@olstad.com> wrote:

> On 28.01.2019 17:52, sergio.fernan...@exoinvesting.com wrote:
> > instance). But I don't know why the rescue tasks never runs.
> >
> > And the role deploy-api/tasks/main.yml looks like this:
> >
> > ---
> > - block:
> >   - name: Create .ssh path for user
> > become: yes
> > file:
> >path: "{{ deploy_path }}/.ssh"
> >owner: example
> >group: example
> >state: directory
> >mode: 0700
> > tags:
> >   - backend
> >   - ssh
> >
> >   - name: Upload RSA public key
> > become: yes
> > template:
> >   src: 'templates/example-id_rsa.pub'
> >   dest: "{{ deploy_path }}/.ssh/authorized_keys"
> >   owner: example
> >   group: example
> >   mode: 0640
> > tags:
> >   - backend
> >   - ssh
> > [ ...More stuff... ]
> >
> > - rescue:
>
> Your syntax is wrong, rescue should not have a dash, check the
> documentation for correct syntax
> https://docs.ansible.com/ansible/latest/user_guide/playbooks_blocks.html
>
> --
> Kai Stian Olstad
>
> --
> 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/2s3HSs_Ke_4/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> ansible-project+unsubscr...@googlegroups.com.
> To post to this group, send email to ansible-project@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/1e5e34a35809bb5b7cd8824e01f54b80%40olstad.com
> .
> 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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAOZL0C8%2B9yrk1F07iReNX-B-3bOORYmPELzjzf%2B3L7-VmpRkRw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Block & rescue misconception

2019-01-28 Thread Kai Stian Olstad

On 28.01.2019 17:52, sergio.fernan...@exoinvesting.com wrote:

instance). But I don't know why the rescue tasks never runs.

And the role deploy-api/tasks/main.yml looks like this:

---
- block:
  - name: Create .ssh path for user
become: yes
file:
   path: "{{ deploy_path }}/.ssh"
   owner: example
   group: example
   state: directory
   mode: 0700
tags:
  - backend
  - ssh

  - name: Upload RSA public key
become: yes
template:
  src: 'templates/example-id_rsa.pub'
  dest: "{{ deploy_path }}/.ssh/authorized_keys"
  owner: example
  group: example
  mode: 0640
tags:
  - backend
  - ssh
[ ...More stuff... ]

- rescue:


Your syntax is wrong, rescue should not have a dash, check the 
documentation for correct syntax

https://docs.ansible.com/ansible/latest/user_guide/playbooks_blocks.html

--
Kai Stian Olstad

--
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1e5e34a35809bb5b7cd8824e01f54b80%40olstad.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Block & rescue misconception

2019-01-28 Thread sergio . fernandez
Hi all,

I'm using Ansible 2.5.11, using the EC2 dynamic inventory script. I'm 
trying to do some tasks over an instance with a role using block and 
rescue, so if one of the tasks fails, the rescue task runs (removing the 
instance). But I don't know why the rescue tasks never runs.

I'm running a playbook which executes the roles, like this:


# Install common packages and tasks, and deploy software
- hosts: tag_Environment_Development:_Role_Pilot:_Name_Backend
  gather_facts: True
  vars_files:
- variables-dev.yml
  roles:
- deploy-api


And the role deploy-api/tasks/main.yml looks like this:

---
- block:
  - name: Create .ssh path for user
become: yes
file:
   path: "{{ deploy_path }}/.ssh"
   owner: example
   group: example
   state: directory
   mode: 0700
tags:
  - backend
  - ssh

  - name: Upload RSA public key
become: yes
template:
  src: 'templates/example-id_rsa.pub'
  dest: "{{ deploy_path }}/.ssh/authorized_keys"
  owner: example
  group: example
  mode: 0640
tags:
  - backend
  - ssh
[ ...More stuff... ]

- rescue:
  - name: Get Temporal Backend Pilot Instance ID
ec2_instance_facts:
  region: "{{ ec2_region }}"
  filters:
"tag:App": EXAMPLE
"tag:Name": Backend Dev
"tag:Role": Pilot
"tag:Environment": Development
"instance-state-name": running
register: ec2_instance_facts_rescue
tags:
  - backend
  - rescue

  - name: Cleanup Pilot instance
ec2:
  aws_access_key: "{{ec2_access_key}}"
  aws_secret_key: "{{ec2_secret_key}}"
  region: "{{ ec2_region }}"
  state: 'absent'
  instance_ids: '{{ ec2_instance_facts_rescue.instances.0.instance_id 
}}'
when: ec2_instance_facts_rescue.instances != ""
tags:
  - backend
  - rescue


But, in fact, the rescue code is never executed.

I'm not sure if I understand correctly how block works, can somebody 
help me?


-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/53e9b895-c0eb-443c-a8f0-4c4f57cc03e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.