From 9a2c887af42f47273d791bad81df90968ab18c84 Mon Sep 17 00:00:00 2001 From: Luca Favatella Date: Wed, 24 May 2017 18:11:19 +0100 Subject: [PATCH 1/5] Print logs in case of error Print system logs (e.g. systemd), Riak errors, Solr logs, Ansible logs. Prefer making Ansible to log to local file instead of [default syslog](https://docs.ansible.com/ansible/intro_configuration.html#log-path) in order not to spam syslog and to ensure printing out of all Ansible logs (e.g. for identifying a "changed" task in the middle while testing Ansible idempotency). --- .travis.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9d95094..359c5bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,8 +19,8 @@ install: # Check ansible version - ansible --version - # Create ansible.cfg with correct roles_path - - 'printf "[defaults]\nroles_path=../" > ansible.cfg' + # Create ansible.cfg with correct roles_path and log file path + - touch ansible.log && { printf "[defaults]\nroles_path=../\nlog_path=ansible.log" > ansible.cfg; } env: - ANSIBLE_HOST_KEY_CHECKING=False @@ -28,6 +28,13 @@ env: script: - ansible-playbook tests/test.yml -v +after_failure: + - sudo tail -n 100 /var/log/syslog + - ls -l /var/log/riak + - ls /var/log/riak/error.log* && cat $(ls -tr /var/log/riak/error.log*) + - ls /var/log/riak/solr.log* && cat $(ls -tr /var/log/riak/solr.log*) + - cat ansible.log + notifications: webhooks: https://galaxy.ansible.com/api/v1/notifications/ slack: From b108d69cc94d3f19448d82d127891f9423a50cb2 Mon Sep 17 00:00:00 2001 From: Luca Favatella Date: Wed, 24 May 2017 16:48:51 +0100 Subject: [PATCH 2/5] Test idempotency Taken from https://github.com/antoiner77/caddy-ansible/blob/464794f4b8109e7e1ee67ec9af9fc2fef7323ed0/.travis.yml#L26-L32 --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 359c5bc..6cd148a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,11 @@ env: script: - ansible-playbook tests/test.yml -v + - > + ansible-playbook tests/test.yml -v + | grep -q 'changed=0.*failed=0' + && (echo 'Idempotence test: pass' && exit 0) + || (echo 'Idempotence test: fail' && exit 1) after_failure: - sudo tail -n 100 /var/log/syslog From c33301277f03b13a7a30a164374713b2db1a7135 Mon Sep 17 00:00:00 2001 From: Luca Favatella Date: Wed, 24 May 2017 17:43:34 +0100 Subject: [PATCH 3/5] Do not report Riak reboot as change ... for idempotency. --- tasks/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/tasks/main.yml b/tasks/main.yml index a8e5f7c..0b46318 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -44,6 +44,7 @@ - name: Reboot Riak to accept the new config and ensure it is enabled to start at bootup service: name=riak enabled=yes state=restarted when: riak_init_system == 'system' + changed_when: False ## This is a workaround for not disrupting idempotency. The proper idempotency fix would be running the task only when the relevant config files changed. - name: Wait for Riak to start up before continuing wait_for: "delay=5 timeout=30 host={{ riak_pb_bind_ip }} port={{ riak_pb_port }} state=started" From 445c13457925d2e77911b9176905950b53ed352f Mon Sep 17 00:00:00 2001 From: Luca Favatella Date: Wed, 24 May 2017 17:52:43 +0100 Subject: [PATCH 4/5] Do not report enquiry of bucket types as change This is a fix towards idempotency. --- tasks/buckets.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/tasks/buckets.yml b/tasks/buckets.yml index d2fcef0..d9ff357 100644 --- a/tasks/buckets.yml +++ b/tasks/buckets.yml @@ -1,6 +1,7 @@ --- - name: Fetch existing bucket-types command: '{{ riak_admin }} bucket-type list' + changed_when: False register: types - name: Create bucket types only if not found in list From ad7875bcae083b5bbaa2403bd2a072887f753d6d Mon Sep 17 00:00:00 2001 From: Luca Favatella Date: Wed, 24 May 2017 18:05:24 +0100 Subject: [PATCH 5/5] Do not report Riak Security management as changes ... for idempotency. --- tasks/security.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tasks/security.yml b/tasks/security.yml index a54856f..3307682 100644 --- a/tasks/security.yml +++ b/tasks/security.yml @@ -7,23 +7,28 @@ command: '{{ riak_admin }} security add-group {{ item }}' with_items: '{{ riak_groups }}' when: riak_groups is defined + changed_when: False ## This is a workaround for not disrupting idempotency. - name: Create users command: '{{ riak_admin }} security add-user {{ item.user }} password={{ item.password }} groups={{ item.groups }}' with_items: "{{ riak_users }}" when: (riak_users is defined) and (riak_groups is defined) + changed_when: False ## This is a workaround for not disrupting idempotency. - name: Create users command: '{{ riak_admin }} security add-user {{ item.user }} password={{ item.password }}' with_items: "{{ riak_users }}" when: (riak_users is defined) and (riak_groups is not defined) + changed_when: False ## This is a workaround for not disrupting idempotency. - name: Create security sources command: '{{ riak_admin }} security add-source {{ item.user }} {{ item.cidr }} {{ item.type }}' with_items: '{{ riak_sources }}' when: riak_sources is defined + changed_when: False ## This is a workaround for not disrupting idempotency. - name: Set security permissions command: '{{ riak_admin }} security grant {{ item.permissions }} on {{ item.scope }} to {{ item.subject }}' with_items: '{{ riak_grants }}' when: riak_grants is defined + changed_when: False ## This is a workaround for not disrupting idempotency.