archive_file fails: Could not open library libarchive.so.13, XZ_5.2 not found (CentOS 7)

The archivefile resource failed on Infra Client 17.7 with LoadError: Could not open library 'libarchive.so.13': /lib64/liblzma.so.5: version `XZ5.2' not found, on CentOS 7 / RHEL 7. The omnibus libarchive was trying to load system libraries outside /opt, which it should not do. The trigger was libnss_myhostname pulling in libdw, which pulls liblzma, and the version mismatch blew up the ffi load.

The root cause is on the OS side: libnssmyhostname on CentOS/RHEL 7 drags in libdw and liblzma, whose versions clash with the omnibus libarchive. The workaround confirmed by a maintainer is to edit /etc/nsswitch.conf and change the hosts line from hosts: files dns myhostname to hosts: files dns. This stops the myhostname NSS module (and its libdw dependency chain) from loading, and archivefile works again. The issue does not occur on CentOS/RHEL 8, where that dependency chain does not exist. Source: https://github.com/chef/chef/issues/12228

Source: https://github.com/chef/chef/issues/12228