# Create Replica
# ------------------------------------------------------------------
- name: Define replica on master and copy checkpoint
hosts: master
user: ec2-user
vars:
p4: "P4TICKETS=/p4/1/.p4tickets /usr/local/bin/p4 -p 1666 -u perforce"
replica_id: replica
service_user: "svc_{{replica_id}}"
tasks:
- name: Include hosts
include_vars:
file: hosts.yaml
name: hosts
- name: create configurables
shell: '{{p4}} configure set "{{replica_id}}#{{item.variable}}={{item.value}}"'
with_items:
- {variable: 'P4TARGET', value: '{{hosts.master_internal}}:1666'}
- {variable: 'db.replication', value: 'readonly'}
- {variable: 'lbr.replication', value: 'readonly'}
- {variable: 'rpl.forward.all', value: '1'}
- {variable: 'rpl.forward.login', value: '1'}
- {variable: 'rpl.compress', value: '4'}
- {variable: 'server', value: '4'}
- {variable: 'monitor', value: '2'}
- {variable: 'serviceUser', value: "{{service_user}}"}
- {variable: 'journalPrefix', value: "/p4/1/checkpoints.{{replica_id}}/p4_1.{{replica_id}}"}
- {variable: 'startup.1', value: 'pull -i 1'}
- {variable: 'startup.2', value: 'pull -u -i 1'}
- {variable: 'startup.3', value: 'pull -u -i 1'}
- {variable: 'startup.4', value: 'pull -u -i 1'}
- {variable: 'startup.5', value: 'pull -u -i 1'}
become: yes
become_user: perforce
- name: define server spec
shell: '{{p4}} --field "Services=replica" server -o {{replica_id}} | {{p4}} server -i'
become: yes
become_user: perforce
- name: Add replica to authorized hosts
shell: ssh-keyscan -H {{hosts.replica_internal}} >> /p4/.ssh/known_hosts
become: yes
become_user: perforce
- name: Run daily_checkpoint too
shell: /p4/common/bin/daily_checkpoint.sh 1
become: yes
become_user: perforce
- name: Record latest checkpoint file
shell: ls -tr /p4/1/checkpoints/*.ckp.*.gz | tail -1
register: ckp_file
become: yes
become_user: perforce
- fetch:
src: "{{ckp_file.stdout_lines[0]}}"
dest: "ckps/"
flat: yes
become: yes
become_user: perforce
# ------------------------------------------------------------------
- name: Copy checkpoint up to replica and start it running
hosts: replica
user: ec2-user
vars:
p4: "P4TICKETS=/p4/1/.p4tickets /usr/local/bin/p4 -p 1666 -u perforce"
replica_id: replica
service_user: "svc_{{replica_id}}"
tasks:
- name: Include hosts
include_vars:
file: hosts.yaml
name: hosts
# - debug: var=hostvars['master']['ckp_file']
- set_fact: ckp_file="{{ hostvars['master']['ckp_file'].stdout_lines[0] | basename }}"
- name: Copy checkpoint to replica
copy:
src: "ckps/{{ ckp_file }}"
dest: /p4/1/checkpoints/
mode: 0600
become: true
become_user: perforce
- name: Create db files
shell: "/p4/1/bin/p4d_1 -r /p4/1/root -z -jr /p4/1/checkpoints/{{ ckp_file }}"
become: yes
become_user: perforce
- name: Login service user to master
shell: "cat /p4/common/config/.p4passwd.p4_1.service | P4TICKETS=/p4/1/.p4tickets /p4/1/bin/p4_1 -p {{ hosts.master_internal }}:1666 -u svc_replica login"
become: yes
become_user: perforce
- name: Create server id
shell: "echo {{ replica_id }}> /p4/1/root/server.id"
become: yes
become_user: perforce
- name: Start Perforce server
shell: /p4/1/bin/p4d_1_init start
become: yes
become_user: perforce