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

Errors in check mode #27

Closed
hhaniel opened this issue Dec 3, 2018 · 8 comments · Fixed by #28
Closed

Errors in check mode #27

hhaniel opened this issue Dec 3, 2018 · 8 comments · Fixed by #28

Comments

@hhaniel
Copy link

hhaniel commented Dec 3, 2018

I am playing with this module for the first time - still slightly inexperienced with ansible but following the instructions and hitting a wall generating ntp.conf

TASK [linux-system-roles.timesync : Generate ntp.conf file] ********************************************
fatal: [tumbleweed-x]: FAILED! => {"changed": false, "msg": "AnsibleFilterError: Version comparison: 'dict object' has no attribute 'stdout'"}

I am trying to get the basics to work and then looking at modifying this role/module to incorporate settings for timekeeper. - I am also looking for options to use this on SLES if possible.

@hairmare
Copy link

hairmare commented Dec 4, 2018

Are you running Ansible with --check? I think this error gets thrown if any of the values in templates/ntp.conf.j2 that should get registered by an earlier skipped task are missing.

I think it's this task that is being skipped in check mode.

timesync/tasks/main.yml

Lines 59 to 65 in d55dd3e

- name: Get ntp version
command: rpm -q --qf '%{version}' ntp
args:
warn: no
register: timesync_ntp_version
changed_when: False
when: timesync_mode != 2 and timesync_ntp_provider == 'ntp'

And this line of the template that would like to use the variable and then proceeds to throw a semi-helpful error message (the stuff about "Version comparison" gave me the hint).

{% if timesync_ntp_version.stdout is version('4.2.6', '<') %}

Does it work if you run it without --check?

@hhaniel
Copy link
Author

hhaniel commented Dec 4, 2018

OK - this seems to have been the issue - I have added a "check_mode: no" in that paragraph so now I can run the whole role in check mode as well. In our environment we need to be able to run everything in check mode. Many Thanx

@hhaniel hhaniel closed this as completed Dec 4, 2018
@pcahyna
Copy link
Member

pcahyna commented Dec 4, 2018

@hhaniel what paragraph do you mean, the "Get ntp version" task? We could add the check_mode: no option. So far we have not tested linux-system-roles for proper check mode support, but we might start in order to help cases like yours.

@hhaniel
Copy link
Author

hhaniel commented Dec 5, 2018

I have added it in line 65:

59 - name: Get ntp version
60 command: rpm -q --qf '%{version}' ntp
61 args:
62 warn: no
63 register: timesync_ntp_version
64 changed_when: False
65 check_mode: no
66 when: timesync_mode != 2 and timesync_ntp_provider == 'ntp'

If you could modify this from your side that would be great since we would like to stick to the core code rather then branching it in our environment.

@hhaniel hhaniel reopened this Dec 5, 2018
@pcahyna pcahyna changed the title Error generating ntp.conf Error generating ntp.conf in check mode Dec 5, 2018
@hhaniel
Copy link
Author

hhaniel commented Dec 6, 2018

The same goes by the way for the chrony version check - I had to do the same there.

@pcahyna
Copy link
Member

pcahyna commented Dec 6, 2018

The same goes by the way for the chrony version check - I had to do the same there.

Yeah, there will be multiple instances of this problem, and in the other roles as well.

@pcahyna pcahyna changed the title Error generating ntp.conf in check mode Errors in check mode Dec 6, 2018
mlichvar added a commit to mlichvar/timesync that referenced this issue Dec 7, 2018
Force the command tasks to run in normal mode in order to allow the role
to run in check mode.

Also, change "False" to "no" for consistency.

Fixes linux-system-roles#27.
@hhaniel
Copy link
Author

hhaniel commented Mar 13, 2019

main.yml.gz

Consider above attached main.yml file - I have made modifications to it so it can run cleanly in check mode and in apply mode. So it checks if certain rpm's are installed before services are enabled or disabled. If a service is not installed (like linuxptp) the specific tasks for them are skipped where they may cause an error or in check mode they will come back as changed even though nothing has changed.

I have only tested this with installing NTP in anger as we do not use any of the other services in our environment yet.

vcrhonek pushed a commit to vcrhonek/timesync that referenced this issue Apr 29, 2019
Force the command tasks to run in normal mode in order to allow the role
to run in check mode.

Also, change "False" to "no" for consistency.

Fixes linux-system-roles#27.
tyll pushed a commit to mlichvar/timesync that referenced this issue May 25, 2019
Force the command tasks to run in normal mode in order to allow the role
to run in check mode.

Fixes linux-system-roles#27.
@tyll tyll closed this as completed in #28 May 25, 2019
pcahyna pushed a commit that referenced this issue May 31, 2019
Force the command tasks to run in normal mode in order to allow the role
to run in check mode.

Fixes #27.
vcrhonek added a commit to vcrhonek/timesync that referenced this issue Sep 30, 2019
linux-system-roles#27 (comment)

Change molecule setup to run check mode at the beginning
(don't forget to change it back to original state later).
@pcahyna
Copy link
Member

pcahyna commented Sep 30, 2019

Hi @hhaniel , thanks for your contribution. I thought that we fixed the check mode issues, but now I see that your change fixes one case that still is not working properly: the case when the role has not been applied previously, and therefore packages assumed to exist are missing. I've opened #51 to track this.

vcrhonek added a commit to vcrhonek/timesync that referenced this issue Oct 7, 2019
linux-system-roles#27 (comment)

Use package_facts to check whether the package is installed and
to determine package version.
vcrhonek added a commit to vcrhonek/timesync that referenced this issue Oct 8, 2019
Based on:
linux-system-roles#27 (comment)
Skip all tasks that assume that some package is installed if it actually isn't.
vcrhonek added a commit to vcrhonek/timesync that referenced this issue Oct 22, 2019
Based on:
linux-system-roles#27 (comment)
Skip all tasks that assume that some package is installed if it actually isn't.
vcrhonek added a commit to vcrhonek/timesync that referenced this issue Oct 30, 2019
Based on:
linux-system-roles#27 (comment)
Skip all tasks that assume that some package is installed if it actually isn't.
vcrhonek added a commit to vcrhonek/timesync that referenced this issue Oct 30, 2019
Based on:
linux-system-roles#27 (comment)
Skip all tasks that assume that some package is installed if it actually isn't.
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.

3 participants