recursively create symlinks with relative paths

198 views
Skip to first unread message

Dan Vaida

unread,
Aug 5, 2014, 1:05:03 PM8/5/14
to ansible...@googlegroups.com
Hello guys,

I am trying to get my head around parsing a folder for its files and creating symlinks for those files found (depth 0) and place them in another directory.

Example: parse sites-available/ and create symlinks in sites-enabled/ with relative paths.

I know one can just use the command/shell modules or even create a task and register the result of a 'ls' command for example and then parse them... but what about the relative path?
One could also use a script like Apache provides for example: a2ensite but what about NGINX?

Trying now the 'with_fileglob' but the task just skips...

Cheers.

Adam Heath

unread,
Aug 5, 2014, 1:07:15 PM8/5/14
to ansible...@googlegroups.com
On debian, I could install the program 'symlinks'. I don't know if it
is available elsewhere. It might be able to help.
> --
> You received this message because you are subscribed to the Google
> Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to ansible-proje...@googlegroups.com
> <mailto:ansible-proje...@googlegroups.com>.
> To post to this group, send email to ansible...@googlegroups.com
> <mailto:ansible...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/2ef77293-7eaf-4c73-8a9e-72ca62b4aef1%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/2ef77293-7eaf-4c73-8a9e-72ca62b4aef1%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Dan Vaida

unread,
Aug 5, 2014, 1:22:56 PM8/5/14
to ansible...@googlegroups.com
Hello,

I also know some non-ansible ways of doing this, but I am interested to see if it can be done entirely in Ansible.

Thanks.

On Aug 5, 2014, at 7:06 PM, Adam Heath <ad...@brainfood.com> wrote:

> On debian, I could install the program 'symlinks'. I don't know if it is available elsewhere. It might be able to help.
>
> On 08/05/2014 12:05 PM, Dan Vaida wrote:
>> Hello guys,
>>
>> I am trying to get my head around parsing a folder for its files and creating symlinks for those files found (depth 0) and place them in another directory.
>>
>> Example: parse sites-available/ and create symlinks in sites-enabled/ with relative paths.
>>
>> I know one can just use the command/shell modules or even create a task and register the result of a 'ls' command for example and then parse them... but what about the relative path?
>> One could also use a script like Apache provides for example: a2ensite but what about NGINX?
>>
>> Trying now the 'with_fileglob' but the task just skips...
>>
>> Cheers.
>> --
>> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email toansible-proj...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> --
> You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/lPawe4hywBA/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/53E10F33.6010303%40brainfood.com.

Michael DeHaan

unread,
Aug 7, 2014, 5:15:25 PM8/7/14
to ansible...@googlegroups.com
I would have a list of what sites to enable and what sites to disable centrally, and do this with a simple with_items instead, because it would be better to have a central record than to have potentially hundreds of different servers each being their own sources of record.

- template: src={{ site }}.cfg dest=/path/to/sites-available
  with_items:  enable_sites

- file: src=... dest=...
  with_items:   enable_sites

- file: src=... state=absent
  with_items: disable_sites









To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.

Dan Vaida

unread,
Nov 26, 2014, 5:16:13 AM11/26/14
to ansible...@googlegroups.com
Thanks Michael and sorry for the late response. This was indeed the path I ended up choosing.


On Thursday, 7 August 2014 23:15:25 UTC+2, Michael DeHaan wrote:
I would have a list of what sites to enable and what sites to disable centrally, and do this with a simple with_items instead, because it would be better to have a central record than to have potentially hundreds of different servers each being their own sources of record.

- template: src={{ site }}.cfg dest=/path/to/sites-available
  with_items:  enable_sites

- file: src=... dest=...
  with_items:   enable_sites

- file: src=... state=absent
  with_items: disable_sites







On Tue, Aug 5, 2014 at 1:22 PM, Dan Vaida <vaid...@gmail.com> wrote:
Hello,

I also know some non-ansible ways of doing this, but I am interested to see if it can be done entirely in Ansible.

Thanks.

On Aug 5, 2014, at 7:06 PM, Adam Heath <ad...@brainfood.com> wrote:

> On debian, I could install the program 'symlinks'.  I don't know if it is available elsewhere.  It might be able to help.
>
> On 08/05/2014 12:05 PM, Dan Vaida wrote:
>> Hello guys,
>>
>> I am trying to get my head around parsing a folder for its files and creating symlinks for those files found (depth 0) and place them in another directory.
>>
>> Example: parse sites-available/ and create symlinks in sites-enabled/ with relative paths.
>>
>> I know one can just use the command/shell modules or even create a task and register the result of a 'ls' command for example and then parse them... but what about the relative path?
>> One could also use a script like Apache provides for example: a2ensite but what about NGINX?
>>
>> Trying now the 'with_fileglob' but the task just skips...
>>
>> Cheers.
>> --
>> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email toansible-proj...@googlegroups.com <mailto:ansible-project+unsub...@googlegroups.com>.
Reply all
Reply to author
Forward
0 new messages