# AWX Template Jobs fail with Permission denied

**URL:** <https://forum.ansible.com/t/awx-template-jobs-fail-with-permission-denied/725>\
**Category:** Get Help\
**Tags:** update, playbook, ubuntu, awx\
**Created:** [September 14, 2023, 12:42pm UTC](https://forum.ansible.com/t/awx-template-jobs-fail-with-permission-denied/725 "2023-09-14T12:42:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmarschall](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/lmarschall/32/564_2.png) [@lmarschall](https://forum.ansible.com/u/lmarschall)\
**Post date:** [September 14, 2023, 12:42pm UTC](https://forum.ansible.com/t/awx-template-jobs-fail-with-permission-denied/725/1 "2023-09-14T12:42:50Z")

</div>

Hey guys,

so I started working with Ansible recently and created some playbooks to update our servers. Using these playbooks from console with Ansible installed on my local pc works fine, but trying to use these playbooks in AWX yields the following result:

```auto
No config file found; using defaults
Skipping callback 'awx_display', as we already have a stdout callback.
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: update_ubuntu_intranet.yaml ******************************************
1 plays in ansible/playbooks/update_ubuntu_intranet.yaml
PLAY [intranet] ****************************************************************
TASK [Gathering Facts] *********************************************************
task path: /runner/project/ansible/playbooks/update_ubuntu_intranet.yaml:1
ok: [monitoring.docsinclouds.com]
TASK [Update all installed packages using APT module] **************************
task path: /runner/project/ansible/playbooks/update_ubuntu_intranet.yaml:5
fatal: [monitoring.docsinclouds.com]: FAILED! => {"changed": false, "msg": "Failed to lock apt for exclusive operation: Failed to lock directory /var/lib/apt/lists/: E:Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)"}
PLAY RECAP *********************************************************************
monitoring.docsinclouds.com : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0   

```

Here is the playbook.yaml

```auto
- hosts: intranet
  become: true
  become_method: sudo
  tasks:
  - name: Update all installed packages using APT module
    apt:
      name: '*'
      state: latest
      update_cache: yes
      only_upgrade: yes
    register: apt_update_status

  - name: Remove packages not needed anymore
    apt:
      autoremove: yes

# - name: Prune everything
# community.docker.docker_prune:
# containers: true
# images: true
# networks: true
# volumes: false
# builder_cache: true

  - name: Reboot when packages were updated
    reboot:
      post_reboot_delay: 60
    when: apt_update_status.changed

```

There’s another problem with installing the docker community package, but that’s for another day 🙂 Thanks in advance.

---

<div class="post-metadata">

**Author:** ![IPvSean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ipvsean/32/1153_2.png) [@IPvSean](https://forum.ansible.com/u/IPvSean)\
**Post date:** [September 14, 2023, 1:23pm UTC](https://forum.ansible.com/t/awx-template-jobs-fail-with-permission-denied/725/2 "2023-09-14T13:23:22Z")

</div>

Is that the only error, it just shows in the job output window that one error? or is the error from an individual task?

---

<div class="post-metadata">

**Author:** ![lmarschall](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/lmarschall/32/564_2.png) [@lmarschall](https://forum.ansible.com/u/lmarschall)\
**Post date:** [September 14, 2023, 1:31pm UTC](https://forum.ansible.com/t/awx-template-jobs-fail-with-permission-denied/725/3 "2023-09-14T13:31:10Z")

</div>

The error is from the individual task, i’ll append the output from the template 👍

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [September 14, 2023, 2:25pm UTC](https://forum.ansible.com/t/awx-template-jobs-fail-with-permission-denied/725/4 "2023-09-14T14:25:54Z")

</div>

Try adding this, before the `apt` task, to check that you are `root`:

```yaml
- name: Check the effective user ID
  ansible.bulitin.assert:
    that:
      - ansible_effective_user_id == 0

```

Because this error:

> E:Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)

Makes me wonder if the task is running as `root`?

---

<div class="post-metadata">

**Author:** ![lmarschall](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/lmarschall/32/564_2.png) [@lmarschall](https://forum.ansible.com/u/lmarschall)\
**Post date:** [September 15, 2023, 9:18am UTC](https://forum.ansible.com/t/awx-template-jobs-fail-with-permission-denied/725/5 "2023-09-15T09:18:55Z")

</div>

Hey @chris ,

thank you so much for your help. I added the task to my playbook, unfortunately it seems like I do not have the sufficient root rights available.

```auto

PLAYBOOK: update_ubuntu_intranet.yaml ******************************************
1 plays in ansible/playbooks/update_ubuntu_intranet.yaml
PLAY [intranet] ****************************************************************
TASK [Gathering Facts] *********************************************************
task path: /runner/project/ansible/playbooks/update_ubuntu_intranet.yaml:1
ok: [monitoring.docsinclouds.com]
TASK [Check the effective user ID] *********************************************
task path: /runner/project/ansible/playbooks/update_ubuntu_intranet.yaml:5
fatal: [monitoring.docsinclouds.com]: FAILED! => {
    "assertion": "ansible_effective_user_id == 0",
    "changed": false,
    "evaluated_to": false,
    "msg": "Assertion failed"
}
PLAY RECAP *********************************************************************
monitoring.docsinclouds.com : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0  

```

---

<div class="post-metadata">

**Author:** ![lmarschall](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/lmarschall/32/564_2.png) [@lmarschall](https://forum.ansible.com/u/lmarschall)\
**Post date:** [September 15, 2023, 9:27am UTC](https://forum.ansible.com/t/awx-template-jobs-fail-with-permission-denied/725/6 "2023-09-15T09:27:53Z")

</div>

It does work now! After realising I do not have the right priviliges, I found this article, [https://groups.google.com/g/awx-project/c/xCmjY\_92nEo](https://groups.google.com/g/awx-project/c/xCmjY_92nEo) and also had the same error, that a “Privilege Escalation Username” was defined on my Credential, after removing this entry, my job template is now running smoothly 🙂 Thank you so much guys 🙏

---

<div class="post-metadata">

**Author:** ![Leo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/leo/32/23_2.png) [@Leo](https://forum.ansible.com/u/Leo)\
**Post date:** [September 15, 2023, 11:14pm UTC](https://forum.ansible.com/t/awx-template-jobs-fail-with-permission-denied/725/7 "2023-09-15T23:14:42Z")

</div>

Hello, welcome and thank you for sharing the solution @lmarschall, it’s really appreciated!

I will tick the issue as solved ✅ with the checkmark in your last comment seeing you have resolved the issue and posted the solution.

By the way, you are welcome to use that any time you open a topic to mark the solution that helped you in the future!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 15, 2023, 11:15pm UTC](https://forum.ansible.com/t/awx-template-jobs-fail-with-permission-denied/725/8 "2023-10-15T23:15:24Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
