Add support replication

Related-PROD:20906

Change-Id: I5935ad8e124ee160bc4e926edfa1418ff71ef307
diff --git a/README.rst b/README.rst
index c97d20b..51410e2 100644
--- a/README.rst
+++ b/README.rst
@@ -276,6 +276,23 @@
       value =  0 No score
       value = +1 Verified
 
+Gerrit replication enable
+
+.. code-block:: yaml
+
+    gerrit:
+      server:
+        plugin:
+          replication:
+            engine: gerrit
+        replication:
+          gerrit2.localdomain:
+            remote_url: user@gerrit2.local.domain:/var/lib/gerrit
+            remote_port: 22
+            replication_user: gerrit2
+
+For creating ssh keys use openssh state
+
 Read more
 =========
 
diff --git a/gerrit/files/replication.config b/gerrit/files/replication.config
new file mode 100644
index 0000000..1841f38
--- /dev/null
+++ b/gerrit/files/replication.config
@@ -0,0 +1,10 @@
+{%- from "gerrit/map.jinja" import server with context %}
+# This file is managed by salt.
+{%- for remote_host, replication in server.get('replication', {}).iteritems() %}
+[remote "{{ remote_host }}"]
+  url = {{ replication.remote_url }}/git/${name}.git
+  push = +refs/*:refs/*
+  threads = 3
+  defaultForceUpdate = false
+  replicatePermissions = true
+{%- endfor%}
diff --git a/gerrit/files/replicaton.config b/gerrit/files/replicaton.config
deleted file mode 100644
index 5d0e04f..0000000
--- a/gerrit/files/replicaton.config
+++ /dev/null
@@ -1,2 +0,0 @@
-{%- from "gerrit/map.jinja" import server with context %}
-# This file is managed by salt.
diff --git a/gerrit/server/service.sls b/gerrit/server/service.sls
index b8fd62f..ac6d3aa 100644
--- a/gerrit/server/service.sls
+++ b/gerrit/server/service.sls
@@ -61,7 +61,7 @@
   - require:
     - file: gerrit_home
 
-{%- if server.plugin.replication is defined %}
+{%- if server.plugin.replication is defined and server.replication is defined %}
 
 {{ server.dir.site }}/etc/replication.config:
   file.managed:
@@ -72,6 +72,16 @@
   - require:
     - file: gerrit_home
 
+{%- for remote_host, replication in server.get('replication', {}).iteritems() %}
+gerrit_remote_known_{{ remote_host }}:
+  ssh_known_hosts.present:
+    - name: {{ remote_host }}
+    - port: {{ replication.remote_port }}
+    - user: {{ replication.replication_user }}
+    - hash_known_hosts: false
+    - require:
+      - file: gerrit_home
+{%- endfor %}
 {% endif %}
 
 {{ server.dir.site }}/etc/ssh_project_rsa_key: