---
- hosts: openzfs-jenkins-public
  tasks:
    - name: Stop the Jenkins instance prior to synchronizing
      become: true
      become_user: "root"
      service:
        name: "jenkins"
        state: "stopped"
    - name: Synchronize the public and private Jenkins instances
      become: true
      become_user: "root"
      synchronize:
        src: /var/lib/jenkins/
        dest: /var/lib/jenkins
        archive: true
        delete: true
        compress: true
    - name: Disable the necessary Jenkins jobs
      become: true
      become_user: "root"
      replace:
        dest: "/var/lib/jenkins/jobs/{{ item }}/config.xml"
        regexp: "<disabled>false</disabled>"
        replace: "<disabled>true</disabled>"
      with_items:
        - "openzfs-regression-tests"
        - "synchronize-jenkins-mirror"
    - name: Start the Jenkins instance after synchronizing completes
      become: true
      become_user: "root"
      service:
        name: "jenkins"
        state: "started"

---
- hosts: openzfs-jenkins-public
  tasks:
    - name: Stop the Jenkins instance prior to synchronizing
      become: true
      become_user: "root"
      service:
        name: "jenkins"
        state: "stopped"
    - name: Synchronize the public and private Jenkins instances
      become: true
      become_user: "root"
      synchronize:
        src: /var/lib/jenkins/
        dest: /var/lib/jenkins
        archive: true
        delete: true
        compress: true
    - name: Remove Jenkins location configuration file
      become: true
      become_user: "root"
      file:
        dest: "/var/lib/jenkins/jenkins.model.JenkinsLocationConfiguration.xml"
        state: "absent"
    - name: Disable the necessary Jenkins jobs
      become: true
      become_user: "root"
      replace:
        dest: "/var/lib/jenkins/jobs/{{ item }}/config.xml"
        regexp: "<disabled>false</disabled>"
        replace: "<disabled>true</disabled>"
      with_items:
        - "openzfs-regression-tests"
        - "synchronize-jenkins-mirror"
    - name: Start the Jenkins instance after synchronizing completes
      become: true
      become_user: "root"
      service:
        name: "jenkins"
        state: "started"

Remove location configuration from synced files
Remove location configuration from synced files

The `JENKINS_URL` needs to be different between the public and private
Jenkins instances, thus we need to remove the synced over location
configuration file from the public Jenkins instance. Otherwise it
`JENKINS_URL` would be the same on the public instance, as it is on the
private instance.
