8

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?

tvl
  • 339
  • 3
  • 4
  • 10

2 Answers2

24

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.

Henrik Pingel
  • 8,676
  • 2
  • 24
  • 38
  • 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
2

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.

Mansur Ul Hasan
  • 264
  • 3
  • 9