Create softlink without source file present

Hi,

Currently, to create softlink, this is what I do:

action: file src=${gSrcSoftlink} dest=${gDestLocation} state=link

This works well if the source file is physically present on the client. However, if the source file is not present at the client, softlink fails. Is there a way where I can softlink even without the source file present? Hence, if the source file were to appear, the softlink would already be there.

Thanks a lot.

from file module docs:

  • force
    force the creation of the symlinks in two cases: the source
    file does not exist (but will appear later); the destination
    exists and a file (so, we need to unlink the “path” file and
    create symlink to the “src” file in place of it). (Choices:
    yes, no)

Hi Brian,

Thanks for your reply. Mine belongs to the first case, the source file does not exist (but will appear later, not sure when exactly). Instead of:
action: file src=${gSrcSoftlink} dest=${gDestLocation} state=link

I changed the action statement to:
action: file state=link path=${gDestLocation} dest=${gSrcSoftlink} force=yes

However, it still fails. msg: src file does not exist. Did i do the wrong thing?

Thanks.
Celine

Sorry typo. Pls refer to below instead:

Hi Brian,

Thanks for your reply. Mine belongs to the first case, the source file does not exist (but will appear later, not sure when exactly). Instead of:
action: file src=${gSrcSoftlink} dest=${gDestLocation} state=link

I changed the action statement to:
action: file state=link path=${gDestLocation} src=${gSrcSoftlink} force=yes

However, it still fails. msg: src file does not exist. Did i do the wrong thing?

Thanks.
Celine

I am using Ansible 1.2. Is “force” a newly added feature? Do i need to upgrade to Ansible 1.3 to use “force”?

I have upgraded to Ansible 1.3. It is working well now. Thanks!

Hi Celene,

Force on some things was not new, but it’s been improved a fair amount, and there were a few 1.2 bugs in the implementation.

I believe before it might have been available on copy and so forth, but highly recommend everyone be on 1.3.X since it contains two months of improvements.

Glad it’s working for you now!

–Michael