[ansible-project] Re: Playbooks In Subdirectories #12862

2018-02-26 Thread Percy Grunwald
Hi Varun,

What are you implying?

On Monday, 26 February 2018 19:08:27 UTC+8, Varun Chopra wrote:
>
> > I feel like most people run their Ansible scripts from the Ansible root 
> directory and mentally treat that as the directory that Ansible should be 
> searching for vars/roles/inventory/etc, _especially_ since the 
> `ansible.cfg` is located there.
>
> Your last two years must've been bloody awful. 
>
> On Monday, February 26, 2018 at 12:31:42 PM UTC+5:30, Percy Grunwald wrote:
>>
>> I've decided to drop my two cents in here as well since I have spent the 
>> past hour trawling Google for advice about this issue and found nothing 
>> that I consider to be an acceptable solution.
>>
>> In my opinion, Ansible's behavior when moving playbooks into a 
>> subdirectory (but still running them from the root directory) is 
>> unintuitive and doesn't seem to match how other programs work. I could 
>> enumerate all of the things that stop working, but I think it's sufficient 
>> to say that the expected behavior for the majority of people would be as 
>> follows:
>>
>> Given that my directory structure is exactly the same as the layout shown 
>> in 
>> http://docs.ansible.com/ansible/latest/playbooks_best_practices.html#directory-layout,
>>  
>> and I am running my scripts from the Ansible root directory like:
>>
>> ```
>> cd /path/to/project/ansible
>> ansible-playbook site.yml
>> ```
>>
>> If I copy `site.yml` into any subdirectory of the Ansible root folder:
>>
>> ```
>> mkdir -p playbooks/subdir
>> cp site.yml playbooks
>> cp site.yml playbook/subdir
>> ```
>>
>> Then the following commands should all be **identical**:
>>
>> ```
>> ansible-playbook site.yml
>> ansible-playbook playbooks/site.yml
>> ansible-playbook playbooks/subdir/site.yml
>> ```
>>
>> In the 2+ years I have been using Ansible, I haven't encountered a 
>> situation where the current default behavior would have been beneficial 
>> compared to the behavior I outlined above. I feel like most people run 
>> their Ansible scripts from the Ansible root directory and mentally treat 
>> that as the directory that Ansible should be searching for 
>> vars/roles/inventory/etc, _especially_ since the `ansible.cfg` is located 
>> there.
>>
>> It would be really great if there was a setting that would make Ansible 
>> behave in the way I have outlined. I would suggest a boolean variable 
>> called something like `lock_working_dir` or `lock_base_dir` that would 
>> "lock" Ansible to the `pwd` when searching for vars/roles/inventory/etc.
>>
>> This would be a huge boon for organization. I'm happy to have a go at 
>> this if this is something that would get considered for PR.
>>
>

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/e21704ad-c48c-48df-898f-2d87b377eadf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Playbooks In Subdirectories #12862

2018-02-26 Thread Varun Chopra
> I feel like most people run their Ansible scripts from the Ansible root 
directory and mentally treat that as the directory that Ansible should be 
searching for vars/roles/inventory/etc, _especially_ since the 
`ansible.cfg` is located there.

Your last two years must've been bloody awful. 

On Monday, February 26, 2018 at 12:31:42 PM UTC+5:30, Percy Grunwald wrote:
>
> I've decided to drop my two cents in here as well since I have spent the 
> past hour trawling Google for advice about this issue and found nothing 
> that I consider to be an acceptable solution.
>
> In my opinion, Ansible's behavior when moving playbooks into a 
> subdirectory (but still running them from the root directory) is 
> unintuitive and doesn't seem to match how other programs work. I could 
> enumerate all of the things that stop working, but I think it's sufficient 
> to say that the expected behavior for the majority of people would be as 
> follows:
>
> Given that my directory structure is exactly the same as the layout shown 
> in 
> http://docs.ansible.com/ansible/latest/playbooks_best_practices.html#directory-layout,
>  
> and I am running my scripts from the Ansible root directory like:
>
> ```
> cd /path/to/project/ansible
> ansible-playbook site.yml
> ```
>
> If I copy `site.yml` into any subdirectory of the Ansible root folder:
>
> ```
> mkdir -p playbooks/subdir
> cp site.yml playbooks
> cp site.yml playbook/subdir
> ```
>
> Then the following commands should all be **identical**:
>
> ```
> ansible-playbook site.yml
> ansible-playbook playbooks/site.yml
> ansible-playbook playbooks/subdir/site.yml
> ```
>
> In the 2+ years I have been using Ansible, I haven't encountered a 
> situation where the current default behavior would have been beneficial 
> compared to the behavior I outlined above. I feel like most people run 
> their Ansible scripts from the Ansible root directory and mentally treat 
> that as the directory that Ansible should be searching for 
> vars/roles/inventory/etc, _especially_ since the `ansible.cfg` is located 
> there.
>
> It would be really great if there was a setting that would make Ansible 
> behave in the way I have outlined. I would suggest a boolean variable 
> called something like `lock_working_dir` or `lock_base_dir` that would 
> "lock" Ansible to the `pwd` when searching for vars/roles/inventory/etc.
>
> This would be a huge boon for organization. I'm happy to have a go at this 
> if this is something that would get considered for PR.
>

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a236b777-d220-485a-8f05-aa2cfa95422c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Playbooks in subdirectories

2016-03-21 Thread Max Kraszewski
Benjamin, Mike:
Thanks for your replies and your advices. 
Now I know I need to reorganize a bit mi playboks and try to follow the 
Ansible best practices more closely.

Thanks in advance!!

Max

El lunes, 21 de marzo de 2016, 12:02:18 (UTC-3), Mike Biancaniello escribió:
>
> I agree that it's annoying, especially if you try to organize by includes 
> and reusable playbooks, it's hard to tell, looking at a list of *.yml files 
> which ones are the top-level and which are meant to be included.
>
> If you're not using roles and only using tasks, you can put your tasks in 
> a tasks/ subfolder and then include them and everything will use the dir 
> of the playbook as the ansible root.
>
> However, if you're using roles, the roles are assumed to be in a subdir of 
> the playbook, so you can either create a playbooks/ subdir and reference 
> your roles like: 
>
> ./stuff.yml
> ---
> - include: playbooks/wtfstuff.yml
>
> playbooks/wtfstuff.yml
> --
> - name: Do wtf stuff
>
>   roles: 
>   - role: ../roles/wtf
>
> or put roles as a subdir of your playbook subdir and then require that any 
> top-level playbooks must only include playbooks from the playbooks/ subdir:
> project
> ├── inventory
> ├── site.yml
> └── playbooks
> ├── ansible.cfg
> ├── webservers.yml
> ├── databases.yml
> └── roles
> ├── nginx
> ├── php
> └── mysql
>
>
>

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/def98cdc-11a6-43de-ae1e-ad3283fc7633%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Playbooks in subdirectories

2016-03-21 Thread Mike Biancaniello
I agree that it's annoying, especially if you try to organize by includes 
and reusable playbooks, it's hard to tell, looking at a list of *.yml files 
which ones are the top-level and which are meant to be included.

If you're not using roles and only using tasks, you can put your tasks in a 
tasks/ subfolder and then include them and everything will use the dir of 
the playbook as the ansible root.

However, if you're using roles, the roles are assumed to be in a subdir of 
the playbook, so you can either create a playbooks/ subdir and reference 
your roles like: 

./stuff.yml
---
- include: playbooks/wtfstuff.yml

playbooks/wtfstuff.yml
--
- name: Do wtf stuff

  roles: 
  - role: ../roles/wtf

or put roles as a subdir of your playbook subdir and then require that any 
top-level playbooks must only include playbooks from the playbooks/ subdir:
project
├── inventory
├── site.yml
└── playbooks
├── ansible.cfg
├── webservers.yml
├── databases.yml
└── roles
├── nginx
├── php
└── mysql


-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/4b54bd1b-e1d9-4b54-a470-3880e0350758%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.