---
- include: update_configrepo.yaml

- stat: path=/root/config/gerrit/replication.config
  register: rstat
- name: Check if replication.config changed
  command: diff /root/config/gerrit/replication.config /home/gerrit/site_path/etc/replication.config
  register: diffstat
  no_log: True
  failed_when: diffstat.rc > 1
- name: Update Gerrit replication.config
  command: cp /root/config/gerrit/replication.config /home/gerrit/site_path/etc/
  when: rstat.stat.exists == True and diffstat.rc == 1
- name: Reload the replication plugin
  command: ssh -p 29418 admin@{{ fqdn }} gerrit plugin reload replication
  when: rstat.stat.exists == True and diffstat.rc == 1
- name: Restart the replication
  command: ssh -p 29418 admin@{{ fqdn }} replication start --all
  when: rstat.stat.exists == True and diffstat.rc == 1

---
- include: update_configrepo.yaml

- stat: path=/root/config/gerrit/replication.config
  register: rstat
- name: Check if replication.config changed
  command: diff /root/config/gerrit/replication.config /home/gerrit/site_path/etc/replication.config
  register: diffstat
  no_log: True
  when: rstat.stat.exists == True
  failed_when: diffstat.rc > 1
- name: Update Gerrit replication.config
  command: cp /root/config/gerrit/replication.config /home/gerrit/site_path/etc/
  when: rstat.stat.exists == True and diffstat.rc == 1
- name: Reload the replication plugin
  command: ssh -p 29418 admin@{{ fqdn }} gerrit plugin reload replication
  when: rstat.stat.exists == True and diffstat.rc == 1
- name: Restart the replication
  command: ssh -p 29418 admin@{{ fqdn }} replication start --all
  when: rstat.stat.exists == True and diffstat.rc == 1

Fix failing diff if /root/config/gerrit/replication.config missing
Fix failing diff if /root/config/gerrit/replication.config missing

If /root/config/gerrit/replication.config is missing the diff will
return with an exit code of 2, and therefore the task will fail.
Due to the earlier stat it's already known if the file exists, so just
checking this using a "when" condition.

Change-Id: I22627f4af1189fdddbef5f8ee8bea5489dd7012f
