Hi, I believe I replied only to the author, so sorry if anyone is seeing
duplicated messages from me.
But try moving the task that failed inside the block. Its currently outside
---
- block:
- name: "status systemd-resolved"
command: systemctl status systemd-resolved
register: resolved_status
rescue:
- name: "Execute this if task 1 fails"
command: echo "Failed"
On Thursday, August 18, 2022 at 12:56:34 PM UTC-3 [email protected] wrote:
> Hard to say without seeing the actual code. This page discusses blocks and
> rescue.
>
> https://docs.ansible.com/ansible/latest/user_guide/playbooks_blocks.html
>
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services, OISM
> Mobile: 202.355.4123 <(202)%20355-4123>
>
> On Aug 18, 2022, at 11:51 AM, SysAdmin EM <[email protected]> wrote:
>
> Hi, sorry for my english, i still learning.
> I need to understand, how its works the blocks and rescue mode in ansible.
>
> I create a playbook similar like this:
> - name: "status systemd-resolved"
> shell:
> cmd: |
> systemctl status systemd-resolved
> register: resolved_status
> - block:
> - name: "Task 1"
> - name: "Task 2"
> rescue:
> - name "Execute this if task 1 fails"
>
> The first task fails because systemd-resolved is not installed:
>
> fatal: [ema-test]: FAILED! => {"changed": true, "cmd": "systemctl status
> systemd-resolved\n", "delta": "0:00:00.039851", "end": "2022-08-18 15:34:04
> .922583", "msg": "non-zero return code", "rc": 3, "start": "2022-08-18
> 15:34:04.882732", "stderr": "", "stderr_lines": [], "stdout": "●
> systemd-reso
> lved.service - Network Name Resolution\n Loaded: loaded
> (/lib/systemd/system/systemd-resolved.service; disabled; vendor preset:
> enabled)\n Drop-I
> n: /lib/systemd/system/systemd-resolved.service.d\n
> └─resolvconf.conf\n Active: inactive (dead)\n Docs:
> man:systemd-resolved.service
> (8)\n
> http://www.freedesktop.org/wiki/Software/systemd/resolved\n
> <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.freedesktop.org%2Fwiki%2FSoftware%2Fsystemd%2Fresolved%2Fn&data=05%7C01%7Cwalter.rowe%40nist.gov%7Cc80774ce44b44299244108da81318c8e%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C637964347056867568%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=mdE42BpMnZvwThZNAwf%2Bl7d1uHxRCi1FA5%2Fg6wKyGQY%3D&reserved=0>
>
> http://www.freedesktop.org/wiki/Software/systemd/writing-netwo
> <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.freedesktop.org%2Fwiki%2FSoftware%2Fsystemd%2Fwriting-netwo&data=05%7C01%7Cwalter.rowe%40nist.gov%7Cc80774ce44b44299244108da81318c8e%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C637964347056867568%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=meQXPoXLd6vrB0E8wNSwQUuVJMxRCX6vdVKGQq6SYmY%3D&reserved=0>
> rk-configuration-managers\n
> http://www.freedesktop.org/wiki/Software/systemd/writing-resolver-clients
> <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.freedesktop.org%2Fwiki%2FSoftware%2Fsystemd%2Fwriting-resolver-clients&data=05%7C01%7Cwalter.rowe%40nist.gov%7Cc80774ce44b44299244108da81318c8e%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C637964347056867568%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=OfBjjJhowjkOTWdSmcTUvAj3al4IYtWPNwHuqs1hyuI%3D&reserved=0>",
>
> "stdout_lines": ["● systemd-resolv
> ed.service - Network Name Resolution", " Loaded: loaded
> (/lib/systemd/system/systemd-resolved.service; disabled; vendor preset:
> enabled)", " Drop
> -In: /lib/systemd/system/systemd-resolved.service.d", "
> └─resolvconf.conf", " Active: inactive (dead)", " Docs:
> man:systemd-resolved
> .service(8)", "
> http://www.freedesktop.org/wiki/Software/systemd/resolved
> <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.freedesktop.org%2Fwiki%2FSoftware%2Fsystemd%2Fresolved&data=05%7C01%7Cwalter.rowe%40nist.gov%7Cc80774ce44b44299244108da81318c8e%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C637964347056867568%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=S6jn%2BQ0Sqz%2BN3rvnHujCPc6h5PpoYKK%2BjvoWZhjZ3bw%3D&reserved=0>",
>
> " http://www.freedesktop.org/wiki/Software/systemd/w
> <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.freedesktop.org%2Fwiki%2FSoftware%2Fsystemd%2Fw&data=05%7C01%7Cwalter.rowe%40nist.gov%7Cc80774ce44b44299244108da81318c8e%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C637964347056867568%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Kt%2Fzt9HjEyX%2B4qAEzs7I5sYCjOYUmPoWnFDkBubJix8%3D&reserved=0>
> riting-network-configuration-managers", "
> http://www.freedesktop.org/wiki/Software/systemd/writing-resolver-clients
> <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.freedesktop.org%2Fwiki%2FSoftware%2Fsystemd%2Fwriting-resolver-clients&data=05%7C01%7Cwalter.rowe%40nist.gov%7Cc80774ce44b44299244108da81318c8e%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C637964347056867568%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=OfBjjJhowjkOTWdSmcTUvAj3al4IYtWPNwHuqs1hyuI%3D&reserved=0>
> "]}
>
> but the rescue never run.
>
> what is my mistake?
>
> my idea is verify if systemd-resolved is installed, if not, i run others
> tasks.
>
> Regards,
>
>
> --
> 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/CAGUDtn%3DJzZ5B5Fh3QPP0rQ3pyQv1XchPzE_rLAcU0OksYezFBQ%40mail.gmail.com
>
> <https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2FCAGUDtn%253DJzZ5B5Fh3QPP0rQ3pyQv1XchPzE_rLAcU0OksYezFBQ%2540mail.gmail.com%3Futm_medium%3Demail%26utm_source%3Dfooter&data=05%7C01%7Cwalter.rowe%40nist.gov%7Cc80774ce44b44299244108da81318c8e%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C637964347057023790%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=QtmkbKAz97EifKloWDj%2FtrjSTy9eaVSFUkFNKc5q18o%3D&reserved=0>
> .
>
>
>
--
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/ddfd3ffa-b01d-497e-9596-27d81e88c7f2n%40googlegroups.com.