Closed benformosa closed 4 years ago
Here's an example of how the mode might be represented as an octal literal. This might be a bit confusing, as this is basically the opposite of how modes are used with the file module etc.
Another, probably simpler approach would be to assume that rsyslog_dircreatemode
will be a string with 4 characters, starting with 0, and never attempt to convert it to an int.
---
- hosts: localhost
gather_facts: false
vars:
# my_mode: 420
my_mode: 0644
tasks:
- name: Display variables
debug:
var: my_mode
- name: Display variable type
debug:
var: my_mode | type_debug
- name: test if my_mode is set correctly
assert:
that:
- my_mode | int is number
- my_format is match('0')
- my_length | int is eq(4)
vars:
my_format: "{{ '{0:04o}'.format(my_mode | int) }}"
my_length: "{{ my_format | length }}"
- name: format as 4-digit number with leading 0
debug:
msg: "mode is: {{ '{0:04o}'.format(my_mode | int) }}"
PLAY [localhost] ***************************************************************
TASK [Display variables] *******************************************************
ok: [localhost] => {
"my_mode": 420
}
TASK [Display variable type] ***************************************************
ok: [localhost] => {
"my_mode | type_debug": "int"
}
TASK [test if my_mode is set correctly] ****************************************
ok: [localhost] => {
"changed": false,
"msg": "All assertions passed"
}
TASK [format as 4-digit number with leading 0] *********************************
ok: [localhost] => {
"msg": "mode is: 0644"
}
PLAY RECAP *********************************************************************
localhost : ok=4 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
You are correct, I've just pushed a commit to fix this. Give CI a bit of time to test everything and I'll release a version when done.
This has been fixed in release 3.0.1, Thanks once again @benformosa for notifying me!
Describe the bug
The
assert.yml
task list asserts that thersyslog_dircreatemode
andrsyslog_filecreatemode
variables should be numbers. Before fa480e94, this assert was| int
, which did pass, but didn't actually test that the variable was set correctly.Rsyslog's documentation specifies:
https://www.rsyslog.com/doc/v8-stable/configuration/action/rsconf1_filecreatemode.html
It might be better to specify the variable as an octal number, then ensure that it is formatted correctly in the template.
Output
https://github.com/robertdebock/ansible-role-rsyslog/runs/1383861975