Issue creating symbolic link

I know this should be trivial, but I just cannot get it to work. I’m trying to create a symbolic link in my playbook. I’m trying to link /etc/guacamole/guacamole.properties in the /usr/share/tomcat/.guacamole directory as follows:

  • name: Config | Creating Tomcat symlink For guacamole.properties
    ansible.builtin.file:
    src: /etc/guacamole/guacamole.properties
    dest: “{{ ‘/usr/share/’ + guacamole_tomcat + ‘/.guacamole’ }}”
    state: link
    owner: “{{ guacamole_tomcat_user }}”
    group: “{{ guacamole_tomcat_user }}”
    mode: 0664
    notify:
  • “Restart {{ guacamole_tomcat_service }}”
  • Kill guacd
  • Restart guacd

But my playbook keeps giving me this error:

refusing to convert from directory to symlink for /usr/share/tomcat/.guacamole

Any ideas on what I’m doing wrong?

Thanks,
Harry

The error can’t be any clearer.
The symlink you’re trying to create already exists as a directory

I’m trying to create it IN /usr/share/tomcat/.guacamole to point to /etc/guacamole/guacamole.properties. Obviously the play isn’t right, but what should it be? Do I need to make the destination “/usr/share/tomcat/.guacamole/guacamole.properties”? Or are the src and dest options reversed? The /etc/guacamole/guacamole.properties is a file and not a directory.

Thanks,
Harry

dest: “{{ ‘/usr/share/’ + guacamole_tomcat + ‘/.guacamole/guacamole.properties’ }}”

You can think of them as reversed if it will help you understand it.

As for the ansible.builtin.file module, the “path” (alias “dest”) is the thing you are creating / modifying / deleting. “src” is what the ASCII arrow points to when you do “ls -l” on the command line.

If you think of “src” as “one end of the ‘ls -l’ arrow”, then they are certainly reversed.
But if you think of “src” as “the source of data when reading from the link”, then “src” makes sense. The “dest” becomes “the place to create the link itself.”

With the strings defined outside the jinja block, it’s a bit clearer:

dest: “/usr/share/{{ guacamole_tomcat }}/.guacamole/guacamole.properties”

Got it! That cleared up my confusion and it’s working now. I.appreciate you guys setting me straight!

Thanks,
Harry