---
- name: Stop PostgreSQL
  service:
    name: "{{ postgresql_service }}"
    state: "stopped"
  become: yes

- name: Remove PostgreSQL data dir
  file: 
    path: "{{ postgresql_data_path }}/main"
    state: absent
  become: yes

- name: Take base backup of PostgreSQL database
  shell: "{{ item }}"
  environment:
    PGPASSWORD: "{{ postgresql_replication_password }}"
  become: yes
  become_user: "{{ postgresql_user }}"
  with_items:
    - pg_basebackup -h {{ postgresql_master_host }} -p {{  postgresql_master_port }} -D {{ postgresql_data_path }}/main -U {{ postgresql_replication_user }} --xlog-method=stream
    - sleep 15

- name: Configure PostgreSQL replication
  template: 
    src: recovery.conf.j2 
    dest: "{{ postgresql_data_path }}/main/recovery.conf"
    owner: "{{ postgresql_user }}"
    group: "{{ postgresql_group }}"
    mode: 0640
  become: yes

---
- name: Stop PostgreSQL
  service:
    name: "{{ postgresql_service }}"
    state: "stopped"
  become: yes

- name: Remove PostgreSQL data dir
  file: 
    path: "{{ postgresql_data_path }}/main"
    state: absent
  become: yes

- name: Take base backup of PostgreSQL database
  shell: "{{ item }}"
  environment:
    PGPASSWORD: "{{ postgresql_replication_password }}"
  become: yes
  become_user: "{{ postgresql_user }}"
  with_items:
    - pg_basebackup -h {{ postgresql_master_host }} -p {{  postgresql_master_port }} -D {{ postgresql_data_path }}/main -U {{ postgresql_replication_user }} -X stream
    - sleep 15

- name: Configure PostgreSQL replication
  template: 
    src: recovery.conf.j2 
    dest: "{{ postgresql_data_path }}/main/recovery.conf"
    owner: "{{ postgresql_user }}"
    group: "{{ postgresql_group }}"
    mode: 0640
  become: yes

Replace "--xlog-method=stream" with "-X stream"
Replace "--xlog-method=stream" with "-X stream"

As of Postgres 10 "--xlog-method" has been replaced with "--wall-method"
but "-X" is compatible with both
