Theoretically, lineinfile should work as you expect. A line is added only if it is not already present in the file.
Is the file a symlink? I do not see the reason why Ansible should not follow this link, but perhaps this could be the reason that it cannot identify the string.
Have you tried adding the regexp parameter? In any case, it will make sense to cover cases where a string like ssl on already exists.
- lineinfile: dest=/etc/pam_ldap.conf line="ssl off" regexp="^ssl\s+"
source share