From 212f960b6378b5046c73139a65a40f744b918ac7 Mon Sep 17 00:00:00 2001 From: Dmitry Shulyak Date: Fri, 25 Sep 2015 10:46:45 +0300 Subject: [PATCH 1/2] Store events separetely from resource --- resources/hosts_file/actions/remove.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 resources/hosts_file/actions/remove.yaml diff --git a/resources/hosts_file/actions/remove.yaml b/resources/hosts_file/actions/remove.yaml new file mode 100644 index 0000000..0c38605 --- /dev/null +++ b/resources/hosts_file/actions/remove.yaml @@ -0,0 +1,5 @@ +- hosts: [{{host}}] + sudo: yes + tasks: + - name: Remove hosts file + shell: rm /etc/hosts From 06c5ce6de74d7323718e58176f8a5a14f698f733 Mon Sep 17 00:00:00 2001 From: Dmitry Shulyak Date: Fri, 25 Sep 2015 15:52:26 +0300 Subject: [PATCH 2/2] Fix several inconsistencies with data and receiver input in case of hash Add example of usage to hosts_file/README.md --- examples/hosts_file/README.md | 61 +++++++++++++++++++++++- resources/hosts_file/actions/remove.yaml | 2 +- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/examples/hosts_file/README.md b/examples/hosts_file/README.md index b3f66ee..6108689 100644 --- a/examples/hosts_file/README.md +++ b/examples/hosts_file/README.md @@ -9,8 +9,8 @@ Then you can continue with standard solar things: ``` solar changes stage -d solar changes process -solar changes run-once last -watch -n 1 solar changes report last +solar or run-once last +watch -n 1 solar or report last ``` Wait until all actions have state `SUCCESS`, @@ -21,3 +21,60 @@ after that check `/etc/hosts` files on both nodes, it will contain entries like: 10.0.0.4 second1441705178.0 ``` +If you want to try out revert functionality - you can do it in a next way: + +After you created all the stuff, print history like this: + +`solar ch history` + +Output: + +``` +log task=hosts_file1.run uid=282fe919-6059-4100-affc-56a2b3992d9d +log task=hosts_file2.run uid=774f5a49-00f1-4bae-8a77-90d1b2d54164 +log task=node1.run uid=2559f22c-5aa9-4c05-91c6-b70884190a56 +log task=node2.run uid=18f06abe-3e8d-4356-b172-128e1dded0e6 +``` + +Now you can try to revert creation of hosts_file1 + +``` +solar ch revert 282fe919-6059-4100-affc-56a2b3992d9d +solar ch stage +log task=hosts_file1.remove uid=1fe456c1-a847-4902-88bf-b7f2c5687d40 +solar ch process +solar or run-once last +watch -n 1 solar or report last +``` + +For now this file will be simply cleaned (more cophisticated task can be added later). +And you can create revert of your revert, which will lead to created hosts_file1 +resource and /etc/hosts with appropriate content + +``` +solar ch revert 282fe919-6059-4100-affc-56a2b3992d9d +solar ch stage +log task=hosts_file1.remove uid=1fe456c1-a847-4902-88bf-b7f2c5687d40 +solar ch process +solar changes run-once last +watch -n 1 solar changes report last +``` + +After this you can revert your result of your previous revert, which will +create this file with relevant content. + +``` +solar ch history -n 1 +log task=hosts_file1.remove uid=1fe456c1-a847-4902-88bf-b7f2c5687d40 +solar ch revert 1fe456c1-a847-4902-88bf-b7f2c5687d40 +solar ch stage +log task=hosts_file1.run uid=493326b2-989f-4b94-a22c-0bbd0fc5e755 +solar ch process +solar changes run-once last +watch -n 1 solar changes report last +``` + + + + + diff --git a/resources/hosts_file/actions/remove.yaml b/resources/hosts_file/actions/remove.yaml index 0c38605..d211b58 100644 --- a/resources/hosts_file/actions/remove.yaml +++ b/resources/hosts_file/actions/remove.yaml @@ -2,4 +2,4 @@ sudo: yes tasks: - name: Remove hosts file - shell: rm /etc/hosts + shell: echo '# flushed by ansible' > /etc/hosts