Daniel
Daniel

Reputation: 17

Create a sym link in ansible

I'm writing a playbook and i want to create a symlink.

While installing citrix on the linux system i need to create a sym link using this command:

ln -s /etc/ssl/serts cacerts

now in the playbook i use it as a :

- name: Link
  command: ln -s /etc/ssl/serts cacerts

The thing is when I use the format above it works fine. But if I want to check if the file exists and if not creating and if yes then skip to the next task.

I could use ignore_errors: yes but I think there is a better way of doing it.

Thank you very much in advance.

Upvotes: 0

Views: 2639

Answers (1)

droperto
droperto

Reputation: 152

You can use the "file" module:

- name: Link
  file:
    src: cacerts
    dest: /etc/ssl/serts
    state: link

It is generally better to use a proper module which will deal with failure conditions and check mode. In this case, it will not fail if the link already exists and it is correct.

You may want to give an absolute src depending on your application.

For more information: https://docs.ansible.com/ansible/latest/modules/file_module.html

Upvotes: 3

Related Questions