virt_net and ignore_errors

14 views
Skip to first unread message

foo

unread,
Jul 1, 2016, 9:44:21 AM7/1/16
to Ansible Project
Hi,
   I've just started using ansible and I wanted to delete the "default" network created in my KVM install.  I'm using the following syntax:

   - name: destroy default network
      virt_net: command=destroy name=default
      ignore_errors: true

    - name: undefine default network
      virt_net: command=undefine name=default
      ignore_errors: true

This works fine, but I had to put in the "ignore_errors: true" flag because if i run this playbook more than once, the second time it will error out as the "default" network does not exist.  On most other ansible tasks, for example when creating a linux user account, ansible will skip over it if the user account already exists and does not error out in the middle of the playbook.

Is there a way to do the same for my destroy and undefine commands in virt_net?  I'm not sure if what i'm doing is the cleanest method.  I know in a perfect world, i would not be running this playbook more than once, but I am running it multiple times testing different additions to the playbook.

Thanks in advance.

Kai Stian Olstad

unread,
Jul 1, 2016, 10:01:57 AM7/1/16
to ansible...@googlegroups.com
On 01. juli 2016 05:20, foo wrote:
> - name: destroy default network
> virt_net: command=destroy name=default
> ignore_errors: true
>
> - name: undefine default network
> virt_net: command=undefine name=default
> ignore_errors: true
>
> This works fine, but I had to put in the "ignore_errors: true" flag because
> if i run this playbook more than once, the second time it will error out as
> the "default" network does not exist. On most other ansible tasks, for
> example when creating a linux user account, ansible will skip over it if
> the user account already exists and does not error out in the middle of the
> playbook.
>
> Is there a way to do the same for my destroy and undefine commands in
> virt_net? I'm not sure if what i'm doing is the cleanest method. I know
> in a perfect world, i would not be running this playbook more than once,
> but I am running it multiple times testing different additions to the
> playbook.

Remove command and add state=absent ?

- name: default network
virt_net: state=absent name=default

--
Kai Stian Olstad

foo

unread,
Jul 1, 2016, 10:16:26 AM7/1/16
to Ansible Project, ansible-pr...@olstad.com
Worked like a champ!!!  Thanks.
Reply all
Reply to author
Forward
0 new messages