no change notify

104 views
Skip to first unread message

anatoly techtonik

unread,
Mar 3, 2014, 1:55:56 PM3/3/14
to ansible...@googlegroups.com
Is it possible to notify handler if task didn't change anything?
I'm creating a backup prior to executing a task, and want to
remove it if nothing changed. Currently I do it like so:

  - command: cp {{backsrc}} {{backdst}}

 
- apt_repository: repo="{{ item }}" state=absent update_cache=false
   
register: aptrem
    with_items
: reporem

 
- apt_repository: repo="{{ item }}" state=present update_cache=false
   
register: aptadd
    with_items
: repoadd

 
- command: rm {{backdst}}
   
when: aptrem.changed == 0 and aptadd.changed == 0

 
- apt: update_cache=true
   
when: aptrem.changed != 0 or aptadd.changed != 0


Serge van Ginderachter

unread,
Mar 3, 2014, 2:00:35 PM3/3/14
to ansible...@googlegroups.com
You could use the changed_when: keyword to set when a task should be seen as 'changed'

changed_when: not aptrem.changed

perhaps?


--
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-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/8c6f7445-646b-4963-85fb-aa4372010c68%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

anatoly techtonik

unread,
Mar 3, 2014, 2:04:40 PM3/3/14
to ansible...@googlegroups.com
changes status is set correctly. I just want to know if it is possible
to use handler + notify instead of passing the state through a variable.
> 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/q5v6DocOg5w/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAEhzMJCS1H8AA%3DJ1_RxjMvdu8UmWqFfMdhLyiC5yaKjgPe1NiA%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/groups/opt_out.



--
anatoly t.

Serge van Ginderachter

unread,
Mar 3, 2014, 2:11:08 PM3/3/14
to ansible...@googlegroups.com

On 3 March 2014 20:04, anatoly techtonik <tech...@gmail.com> wrote:
changes status is set correctly. I just want to know if it is possible
to use handler + notify instead of passing the state through a variable.

Handlers get triggered on a changed state, from what you said, you want to trigger it when 'not changed', so hence my example.
There's no way to trigger a handler while keeping the changed: false state.

I'll agree that the changed states get weird in this case :)​


Serge

anatoly techtonik

unread,
Mar 3, 2014, 2:26:07 PM3/3/14
to ansible...@googlegroups.com
Yes. I better keep my approach. =)
Reply all
Reply to author
Forward
0 new messages