Ansible, "copy" module and "become"

Posted by ads on Thursday, 2021-04-15
Posted in [Ansible]

For testing I did spin up a couple of new virtual (Ubuntu 20.04 LTS) instances, installed PostgreSQL, and wanted to copy over a .sql file to install in the database:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
- name: copy files to PostgreSQL data directory
  copy:
    src: "files/{{ item }}"
    dest: "{{ item }}"
    mode: 0700
  become: yes
  become_user: postgres
  loop:
    - file1.sql
    - file2.sql

And ran into a meaningless error message:

TASK [copy files to PostgreSQL data directory] ***********
fatal: [xxx.xxx.xxx.xxx]: FAILED! => {"msg": "Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user (rc: 1, err: chown: changing ownership of '/var/tmp/ansible-tmp-1618521951.848439-176484068031965/': Operation not permitted\nchown: changing ownership of '/var/tmp/ansible-tmp-1618521951.848439-176484068031965/source': Operation not permitted\n}). For information on working around this, see https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user"}

The solution to this problem is rather easy, but not straighforward: the acl package is missing.

1
2
3
4
5
6
- name: Install additional packages
  apt:
    name:
      - sudo
      - acl
    state: present

Once this package is installed, the copy works as expected. The Ansible error message is misleading.


Categories: [Ansible]

Share: