harbor run -t scale-ai/hil-bench-swe_66-full_infoharbor download scale-ai/hil-bench-swe_66-full_infoansible.builtin.password fails on subsequent runs when ident is saved in the password file.When using lookup('ansible.builtin.password', ...) with an encryption method that supports an ident parameter, the first run correctly saves the password along with its metadata in the file. However, on subsequent executions, the lookup fails because previously saved values are not correctly parsed from the file. This leads to unhandled exceptions when trying to re-encrypt using bcrypt or other algorithms.
First run creates the password file with the password and associated encryption metadata.
Second run fails with an unhandled exception when metadata is present in the saved file. Example:
$ ansible -m debug -a "msg={{lookup('ansible.builtin.password', 'password.txt encrypt=bcrypt')}}" localhost
[WARNING]: No inventory was parsed, only implicit localhost is available
localhost | FAILED! => {
"msg": "An unhandled exception occurred while running the lookup plugin 'ansible.builtin.password'. Error was an unexpected exception related to invalid characters in bcrypt salt."
}
On subsequent runs, the lookup should read and interpret the password file correctly, handling all stored metadata appropriately for re-encryption.
The password lookup plugin parses password files containing password and associated metadata values, returning parsed components and treating missing values as None.
Password file operations are idempotent - repeated executions with the same parameters produce the same result without modifying the file content unnecessarily.
When a password file contains an ident value, subsequent runs reuse that stored ident rather than generating a new one or duplicating the entry in the file.
Password files are updated atomically to prevent corruption during concurrent access by multiple processes.
The plugin handles empty or missing password files by generating appropriate password, salt, and ident values based on the encryption method specified.
Password file format supports storing and retrieving password and metadata values in a way that allows reliable parsing on subsequent reads.
Error handling should provide clear messages when password file processing or encryption operations encounter failures, wrapping underlying library exceptions into user-friendly errors.
Providing an ident parameter to the lookup directs the plugin to use that identifier for the encryption algorithm.
No new interfaces are introduced.
Passlib raises ValueError when it encounters invalid input parameters such as a malformed salt or ident value. Catch specifically ValueError in the PasslibHash._hash method's hashing calls and convert it to an AnsibleError. Catching a different type (e.g., TypeError, OSError) would fail to intercept the actual crash, and catching broadly (e.g., Exception) would mask unrelated bugs.
The lock-protected region (try/finally block) must encompass only file operations: reading, parsing, and writing the password file. The encryption call (do_encrypt/passlib_or_crypt) must be placed outside and after the finally block that releases the lock. This preserves the original code's sequencing where the lock is released before encryption begins, preventing unnecessary lock contention during the expensive hashing operation.
The ident value must be extracted exclusively from the portion of file content that follows the salt delimiter, never from the original full content. First, locate the salt delimiter and separate everything after it from the password. Then, search for the ident marker only within that post-salt portion. If found, the ident value is the text after the ident marker and the salt is the text before it within that portion. If the ident marker is not found in the post-salt portion, the entire portion is the salt value and ident is None.
The stored ident from the password file takes precedence over both the user-provided ident parameter and the encryption algorithm's default. If a stored ident exists and the user provides a different ident, the plugin must raise an error indicating the conflict between the two values. If no stored ident exists, the user-provided ident is used. If neither a stored nor user-provided ident exists, the encryption algorithm's implicit default ident is used as a last resort, and the file should be marked as changed for rewriting.