[GH-ISSUE #88] [BUG] Role fails with "AnsibleUndefinedVariable: 'dict object' has no attribute 'systemd'" #41

Closed
opened 2026-03-03 13:58:38 +03:00 by kerem · 3 comments
Owner

Originally created by @PorgJuice on GitHub (Oct 25, 2020).
Original GitHub issue: https://github.com/konstruktoid/hardening/issues/88

Originally assigned to: @konstruktoid on GitHub.

Sorry if I'm missing something obvious here but I'm new to Ansible. I'm running into an issue doing a dry run of this role.

Describe the bug
When running the role (with --check') on a new Ubuntu 20.04 VM in Proxmox, it fails on timesyncd.confwithAnsibleUndefinedVariable: 'dict object' has no attribute 'systemd'`.

To Reproduce
Build a brand new Ubuntu 20.04 VM and do a dry run (--check) of the role on it.

Expected behavior
To run without crashing.

System (lsb_release -a):

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:        20.04
Codename:       focal

Additional context

# playbook.yml
- name: 'Provision Image'
  hosts: all
  roles:
    - { 
      role: konstruktoid.hardening, 
      sshd_port: 56789
      }
  become: true
  remote_user: toor
Originally created by @PorgJuice on GitHub (Oct 25, 2020). Original GitHub issue: https://github.com/konstruktoid/hardening/issues/88 Originally assigned to: @konstruktoid on GitHub. Sorry if I'm missing something obvious here but I'm new to Ansible. I'm running into an issue doing a dry run of this role. **Describe the bug** When running the role (with `--check') on a new Ubuntu 20.04 VM in Proxmox, it fails on `timesyncd.conf` with `AnsibleUndefinedVariable: 'dict object' has no attribute 'systemd'`. **To Reproduce** Build a brand new Ubuntu 20.04 VM and do a dry run (`--check`) of the role on it. **Expected behavior** To run without crashing. **System (lsb_release -a):** ``` No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04 LTS Release: 20.04 Codename: focal ``` **Additional context** ``` # playbook.yml - name: 'Provision Image' hosts: all roles: - { role: konstruktoid.hardening, sshd_port: 56789 } become: true remote_user: toor ```
kerem closed this issue 2026-03-03 13:58:38 +03:00
Author
Owner

@konstruktoid commented on GitHub (Oct 26, 2020):

Hi @ProfessorSalty, thanks for reporting the issue. I'll have a look at it, but I assume it was meant to be opened in https://github.com/konstruktoid/ansible-role-hardening

<!-- gh-comment-id:716398192 --> @konstruktoid commented on GitHub (Oct 26, 2020): Hi @ProfessorSalty, thanks for reporting the issue. I'll have a look at it, but I assume it was meant to be opened in https://github.com/konstruktoid/ansible-role-hardening
Author
Owner

@konstruktoid commented on GitHub (Oct 26, 2020):

Since the --check doesn't actually change anything, the custom facts directories and files aren't created. This results in the ansible_local.systemd.version and related facts are missing.

~$ ls -l /etc/ansible/facts.d/systemd.fact
ls: cannot access '/etc/ansible/facts.d/systemd.fact': No such file or directory

The --check will also fail on anything that requires some kind of interaction:

fatal: [127.0.0.1]: FAILED! => {"msg": "The conditional check 'needrestart_directory.stat.exists and needrestart_restart_set.rc != 0' failed. The error was: error while evaluating conditional (needrestart_directory.stat.exists and needrestart_restart_set.rc != 0): 'dict object' has no attribute 'rc'\n\nThe error appears to be in '/private/etc/ansible/roles/konstruktoid.hardening/tasks/packages.yml': line 42, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: configure needrestart\n  ^ here\n"}
<!-- gh-comment-id:716423338 --> @konstruktoid commented on GitHub (Oct 26, 2020): Since the `--check` doesn't actually change anything, the custom facts directories and files aren't created. This results in the `ansible_local.systemd.version` and related facts are missing. ``` ~$ ls -l /etc/ansible/facts.d/systemd.fact ls: cannot access '/etc/ansible/facts.d/systemd.fact': No such file or directory ``` The `--check` will also fail on anything that requires some kind of interaction: ``` fatal: [127.0.0.1]: FAILED! => {"msg": "The conditional check 'needrestart_directory.stat.exists and needrestart_restart_set.rc != 0' failed. The error was: error while evaluating conditional (needrestart_directory.stat.exists and needrestart_restart_set.rc != 0): 'dict object' has no attribute 'rc'\n\nThe error appears to be in '/private/etc/ansible/roles/konstruktoid.hardening/tasks/packages.yml': line 42, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: configure needrestart\n ^ here\n"} ```
Author
Owner

@PorgJuice commented on GitHub (Oct 26, 2020):

Ah, yes, I suppose this is the wrong repo. Sorry about that. I appreciate you taking your time out for the explanation - it looks like I can't just blindly check my tasks, so I'll have to modify my config to account for missing facts. Thanks so much!

<!-- gh-comment-id:716591793 --> @PorgJuice commented on GitHub (Oct 26, 2020): Ah, yes, I suppose this is the wrong repo. Sorry about that. I appreciate you taking your time out for the explanation - it looks like I can't just blindly check my tasks, so I'll have to modify my config to account for missing facts. Thanks so much!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hardening#41
No description provided.