Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install bootstrap packages mkstemp (13: Permission denied) #63

Open
patsevanton opened this issue Apr 1, 2022 · 6 comments
Open

install bootstrap packages mkstemp (13: Permission denied) #63

patsevanton opened this issue Apr 1, 2022 · 6 comments

Comments

@patsevanton
Copy link

patsevanton commented Apr 1, 2022

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)"
@frock81
Copy link

frock81 commented Jun 27, 2022

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
Copy link

frock81 commented Jun 27, 2022

Sorry. Just now, saw the pull request.

@jacobemery
Copy link

+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.

@qs5779
Copy link

qs5779 commented Jul 21, 2022

+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

@akamuza
Copy link

akamuza commented Sep 19, 2022

+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
Copy link

akamuza commented Sep 19, 2022

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
    - .....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants