ansible-role-bootstrap icon indicating copy to clipboard operation
ansible-role-bootstrap copied to clipboard

install bootstrap packages mkstemp (13: Permission denied)

Open patsevanton opened this issue 2 years ago • 6 comments

Describe the bug

Could not create temporary file for /var/lib/apt/extended_states - mkstemp (13: Permission denied)

Run playbook from user with sudo without password

Playbook

---
- name: Install zabbix server and web
  hosts: zabbix
  become: true

  roles:
    - role: robertdebock.bootstrap

Output

TASK [robertdebock.bootstrap : install bootstrap packages (package)] *******************************************************************************************************************
Friday 01 April 2022  14:04:06 +0600 (0:00:01.796)       0:00:11.819 **********
failed: [zabbix] (item=python3) => changed=false
  ansible_loop_var: item
  item: python3
  msg: |-
    '/usr/bin/apt-mark manual python3' failed: E: Could not create temporary file for /var/lib/apt/extended_states - mkstemp (13: Permission denied)
    E: Failed to write temporary StateFile /var/lib/apt/extended_states
  rc: 100
  stderr: |-
    E: Could not create temporary file for /var/lib/apt/extended_states - mkstemp (13: Permission denied)
    E: Failed to write temporary StateFile /var/lib/apt/extended_states
  stderr_lines: <omitted>
  stdout: ''
  stdout_lines: <omitted>
failed: [zabbix] (item=sudo) => changed=false
  ansible_loop_var: item
  item: sudo
  msg: |-
    '/usr/bin/apt-mark manual sudo' failed: E: Could not create temporary file for /var/lib/apt/extended_states - mkstemp (13: Permission denied)
    E: Failed to write temporary StateFile /var/lib/apt/extended_states
  rc: 100
  stderr: |-
    E: Could not create temporary file for /var/lib/apt/extended_states - mkstemp (13: Permission denied)
    E: Failed to write temporary StateFile /var/lib/apt/extended_states
  stderr_lines: <omitted>
  stdout: ''
  stdout_lines: <omitted>
failed: [zabbix] (item=gnupg) => changed=false
  ansible_loop_var: item
  item: gnupg
  msg: |-
    '/usr/bin/apt-mark manual gnupg' failed: E: Could not create temporary file for /var/lib/apt/extended_states - mkstemp (13: Permission denied)
    E: Failed to write temporary StateFile /var/lib/apt/extended_states
  rc: 100
  stderr: |-
    E: Could not create temporary file for /var/lib/apt/extended_states - mkstemp (13: Permission denied)
    E: Failed to write temporary StateFile /var/lib/apt/extended_states
  stderr_lines: <omitted>
  stdout: ''
  stdout_lines: <omitted>

Environment

Version

ansible [core 2.12.2]
  python version = 3.8.10 (default, Nov 26 2021, 20:14:08) [GCC 9.3.0]

Server where ansible

cat /etc/*release*
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.3 LTS"
NAME="Ubuntu"
VERSION="20.04.3 LTS (Focal Fossa)"

Remote server

cat /etc/*release*
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.3 LTS"
NAME="Ubuntu"
VERSION="20.04.3 LTS (Focal Fossa)"

patsevanton avatar Apr 01 '22 08:04 patsevanton

I experienced this same issue today. Same OS and release, Ubuntu Focal. Ansible version 2.13.1 and Python 3.8.10 (from package distro). The problem occurs in the task install bootstrap packages (package) in the tasks/main.yml file. If i change the become: no to become: yes from the surrounding block, things run without failures, but I don't know about the implications of that.

frock81 avatar Jun 27 '22 03:06 frock81

Sorry. Just now, saw the pull request.

frock81 avatar Jun 27 '22 03:06 frock81

+1 for RHEL

failed: [hostname] (item=python3) => {"ansible_loop_var": "item", "changed": false, "item": "python3", "msg": "This command has to be run under the root user.", "results": []} failed: [hostname] (item=sudo) => {"ansible_loop_var": "item", "changed": false, "item": "sudo", "msg": "This command has to be run under the root user.", "results": []}

Changed robertdebock.bootstrap/tasks/main.yaml, last task, install bootstrap packages (package) changed: "become: no" to "become: True" and everything worked swimmingly.

I see there was a pull request, but it was closed.

jacobemery avatar Jul 06 '22 04:07 jacobemery

+1 for Debian

ansible [core 2.13.1]

cat /etc/os-release PRETTY_NAME="Debian GNU/Linux 11 (bullseye)" NAME="Debian GNU/Linux" VERSION_ID="11" VERSION="11 (bullseye)" VERSION_CODENAME=bullseye ID=debian

qs5779 avatar Jul 21 '22 18:07 qs5779

+1 for Ubuntu

cat /etc/os-release PRETTY_NAME="Ubuntu 22.04.1 LTS" NAME="Ubuntu" VERSION_ID="22.04" VERSION="22.04.1 LTS (Jammy Jellyfish)" VERSION_CODENAME=jammy ID_LIKE=debian UBUNTU_CODENAME=jammy

akamuza avatar Sep 19 '22 16:09 akamuza

Actually this issue can be resolved just by using ansible_become: yes with no modification to source files:

---
- hosts: all
  gather_facts: no
  vars:
    ansible_become: yes

  roles:
    - role: robertdebock.bootstrap
    - .....

akamuza avatar Sep 19 '22 16:09 akamuza