Skip to content

Make terminfo role idempotent - #2

Open
remmelt wants to merge 1 commit into
moreati:mainfrom
remmelt:fix-terminfo-idempotency
Open

Make terminfo role idempotent#2
remmelt wants to merge 1 commit into
moreati:mainfrom
remmelt:fix-terminfo-idempotency

Conversation

@remmelt

@remmelt remmelt commented Nov 18, 2025

Copy link
Copy Markdown

Fixes #1

Summary

The terminfo role previously always reported "changed" on every playbook run due to hardcoded changed_when: true. This PR makes the role idempotent by comparing the local and remote terminfo entries before running tic.

Changes

  1. Added task to read remote terminfo entry: Uses infocmp -x to read the existing terminfo entry from the target system
  2. Graceful handling of missing entries: Sets failed_when: false so the task succeeds even when the terminfo entry doesn't exist yet
  3. Conditional execution: The tic command now only runs when:
    • The remote terminfo entry doesn't exist (rc != 0), OR
    • The local and remote entries differ (content comparison)

Benefits

  • Eliminates noise in playbook output
  • Makes it easier to identify actual configuration changes
  • Follows Ansible best practices for idempotency
  • No functional changes to the role's behavior

Testing

The logic has been implemented to:

  • Skip running tic when the terminfo entry is already up to date
  • Run tic when the entry is missing or differs from the local version
  • Properly report "changed" status only when changes are made

Fixes moreati#1

The role previously always reported "changed" on every run due to
hardcoded `changed_when: true`. This change makes the role idempotent
by:

1. Reading the remote terminfo entry (if it exists)
2. Comparing local vs remote entries
3. Only running `tic` when they differ or remote entry doesn't exist

The `tic` command now only runs when:
- The remote terminfo entry doesn't exist (rc != 0), OR
- The local and remote entries differ

This eliminates noise in playbook output and makes it easier to
identify actual configuration changes.
@remmelt

remmelt commented Dec 7, 2025

Copy link
Copy Markdown
Author

Looks good?

- "{{ terminfo_term_name }}"
register: terminfo_remote_infocmp_result
changed_when: false
failed_when: false

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not keen on this. What if infocmp isn't found? Or some file permission error occurs?

@moreati

moreati commented Dec 7, 2025

Copy link
Copy Markdown
Owner

Looks good?

Sorry, TIL only I could see the comment I left a few weeks ago

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 this pull request may close these issues.

terminfo role always reports "changed" due to hardcoded changed_when: true

2 participants