{"id":1864,"date":"2017-05-04T16:18:57","date_gmt":"2017-05-04T21:18:57","guid":{"rendered":"http:\/\/osric.com\/chris\/accidental-developer\/?p=1864"},"modified":"2017-05-04T16:18:57","modified_gmt":"2017-05-04T21:18:57","slug":"ansible-meta-action-error-conflicting-action-statements","status":"publish","type":"post","link":"https:\/\/osric.com\/chris\/accidental-developer\/2017\/05\/ansible-meta-action-error-conflicting-action-statements\/","title":{"rendered":"Ansible meta action: &#8220;ERROR! conflicting action statements&#8221;"},"content":{"rendered":"<p>The initial problem I was trying to solve had to do with a reboot role. Although it was the last role listed, once it ran the connection would be broken and then none of the notified tasks from previous roles would run.<\/p>\n<p>Under normal circumstances, handlers are run after all the roles. One idea I had was to have to reboot role contain a trivial task, which would notify a handler that contained the actual reboot task. Presumably as the last task notified, it would run last.<\/p>\n<p>While I was looking at ways to do this, I discovered Ansible meta actions:<br \/>\n<a href=\"https:\/\/docs.ansible.com\/ansible\/meta_module.html\">Ansible Documentation: Meta Module<\/a><\/p>\n<p>The <code>flush_handlers<\/code> action looked like just what I needed:<\/p>\n<pre><code>    meta: flush_handlers<\/code><\/pre>\n<p>I tried adding that to my reboot task so that it would run all of the previously notified handlers:<\/p>\n<pre><code>- name: Rebooting ...\r\n  command: shutdown -r now \"Ansible says: Time for a reboot\"\r\n  meta: flush_handlers<\/code><\/pre>\n<p>This produced an error:<br \/>\n<code>ERROR! conflicting action statements<\/code><\/p>\n<p>As I looked at the documentation a little more closely, I saw that the examples have <code>meta<\/code> as a separate task, not part of an existing task. I missed that at first glance because of the lack of line spacing in the examples, e.g. compare:<\/p>\n<pre><code>- template:\r\n    src: new.j2\r\n    dest: \/etc\/config.txt\r\n  notify: myhandler\r\n- name: force all notified handlers to run at this point, not waiting for normal sync points\r\n  meta: flush_handlers<\/code><\/pre>\n<p>to<\/p>\n<pre><code>- template:\r\n    src: new.j2\r\n    dest: \/etc\/config.txt\r\n  notify: myhandler\r\n\r\n- name: force all notified handlers to run at this point, not waiting for normal sync points\r\n  meta: flush_handlers<\/code><\/pre>\n<p>I updated my reboot task accordingly:<\/p>\n<pre><code>- name: Force handlers to run before rebooting\r\n  meta: flush_handlers\r\n\r\n- name: Rebooting ...\r\n  command: shutdown -r now \"Ansible says: Time for a reboot\"<\/code><\/pre>\n<p>I tested the playbook with the revised role and confirmed that all notified handlers from previous roles ran before the systems rebooted.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While using Ansible&#8217;s meta action, flush_handlers, I ran into a problem where I inadvertently tried to add the meta action to an existing command action. This post looks at my reasons for using the flush_handlers meta action, the Ansible error, and how to correct the error. Along the way I reveal my inability to read documentation closely.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[439],"tags":[423,441,440],"class_list":["post-1864","post","type-post","status-publish","format-standard","hentry","category-ansible","tag-ansible","tag-flush_handlers","tag-handlers"],"_links":{"self":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1864","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/comments?post=1864"}],"version-history":[{"count":6,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1864\/revisions"}],"predecessor-version":[{"id":1873,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1864\/revisions\/1873"}],"wp:attachment":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/media?parent=1864"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/categories?post=1864"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/tags?post=1864"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}