4

I have a dead symlink named dead_symlink under the directory /usr/local/bin

When Ansible check the file it reports it exists

- stat: "path=/usr/local/bin/dead_symlink"
  register: dead_symlink_bin

- debug: var=dead_symlink_bin.stat.exists

But when I try to remove it, it reports 'ok' but nothing is happening (the symlink is still there)

- name: Remove symlink
  file:
    path: "path=/usr/local/bin/dead_symlink"
    state: absent

What am I doing wrong?

  • run the tas in debug -vv and add the output to your question. The command is IMHO correct. – Henrik Pingel Aug 10 '16 at 15:47
17

You have a synatx error in your task. It should be:

- name: Remove symlink
  file:
   path: "/usr/local/bin/dead_symlink"
   state: absent

Ansible is probably looking for the path path=/usr/local/bin/dead_symlink and not for /usr/local/bin/dead_symlink.

  • hahaha, true! feel so stupid for a typo... And I've spend some hours on that... Thanks again! – tvl Aug 10 '16 at 15:51
  • yeah, looks like a simple copy&paste mistake. I still wonder why Ansible interpreted that as a vaild path. First step should be always to run in debug than you can see the commands Ansible is executing. – Henrik Pingel Aug 10 '16 at 15:53
  • Yes it was a copy paste mistake from the - stat: "path=/usr/local/bin/dead_symlink". I run the debug, I read many times the output but I stack and never see it :P Thanks again! – tvl Aug 10 '16 at 16:07
0

For me in playbook

- name: Deleting Default Configurations
  when: sitelink is success
  file: path=/etc/nginx/site-enabled/default state=absent

above code is working nice for me just replace with your path.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.