---
- name: "Pre-upgrade | check if old credential dir exists"
  local_action:
    module: stat
    path: "{{ inventory_dir }}/../credentials"
  vars:
    ansible_python_interpreter: "/usr/bin/env python"
  register: old_credential_dir
  become: no

- name: "Pre-upgrade | check if new credential dir exists"
  local_action:
    module: stat
    path: "{{ inventory_dir }}/credentials"
  vars:
    ansible_python_interpreter: "/usr/bin/env python"
  register: new_credential_dir
  become: no
  when: old_credential_dir.stat.exists

- name: "Pre-upgrade | move data from old credential dir to new"
  local_action: command mv {{ inventory_dir }}/../credentials {{ inventory_dir }}/credentials
  args:
    creates: "{{ inventory_dir }}/credentials"
  vars:
    ansible_python_interpreter: "/usr/bin/env python"
  become: no
  when: old_credential_dir.stat.exists and not new_credential_dir.stat.exists

---
- name: "Pre-upgrade | check if old credential dir exists"
  stat:
    path: "{{ inventory_dir }}/../credentials"
  delegate_to: localhost
  register: old_credential_dir
  become: no

- name: "Pre-upgrade | check if new credential dir exists"
  stat:
    path: "{{ inventory_dir }}/credentials"
  delegate_to: localhost
  register: new_credential_dir
  become: no
  when: old_credential_dir.stat.exists

- name: "Pre-upgrade | move data from old credential dir to new"
  command: mv {{ inventory_dir }}/../credentials {{ inventory_dir }}/credentials
  args:
    creates: "{{ inventory_dir }}/credentials"
  delegate_to: localhost
  become: no
  when: old_credential_dir.stat.exists and not new_credential_dir.stat.exists

Use delegate_to: localhost instead of local_action
Use delegate_to: localhost instead of local_action

Allow to use `ansible_become: true` (#2969)
And set it to `false` for `localhost` with an `host_var`
