Thanks, Igor. This has been great. It sounds like you're saying I 
can't/shouldn't use an inventory file at all, but explicitly pass an extra 
var  for the environment. Rather than dropping conditionals everywhere I 
need env-specific values, is there any way to get Ansible to use that env 
value to automatically read variables from a file? Originally, it seemed 
like group_vars made the most sense, but if an inventory file doesn't make 
sense, I'm not sure group_vars make sense either.

Thanks again.

On Sunday, October 25, 2015 at 9:18:09 PM UTC-4, Igor Cicimov wrote:
>
> Well as I expected this might be little bit confusing to a beginner. So 
> basically the answer to your question was: tag the instances you create 
> based on the environment you are creating them in and then use that tag for 
> the configuration task(s).
>
> Which means you need to base the exact_count on the parameter you want to 
> group on, in this case the environment tag:
>
>     exact_count: "5"
>     count_tag:
>       Env: "prod"
>
> In this way when ever you run the creation playbook it will check if there 
> are exactly 5 instances with tag named Env and value of prod and if no will 
> create them and if yes will skip the creation task.
>
> There aren't any "tons" of input vars in my example, it is just the 
> environment tag name you want to run the playbook for. Very simple.
>
> For the configuration playbook as I said you just need to use:
>
> - hosts: tag_Env_<prod|staging|dev>
>
> to configure the ec2 instances you have created for the environment.
>
> Sorry I really don't know how to better explain this to a beginner. Don't 
> get discouraged though keep working and when you come back to this post in 
> couple of weeks when you master Ansible it will all be crystal clear :-)
>
> On Monday, October 26, 2015 at 5:51:09 AM UTC+11, Rob Wilkerson wrote:
>>
>> I've been running this over in my head and I think I'm more confused than 
>> ever. I don't really care whether I specifically use dynamic inventory or 
>> any other specific technique. I care that my script is idempotent, 
>> reasonably simple to execute for any developer and somewhat consistent with 
>> Ansible recommendations. \
>>
>> If I run the staging deployment, it should create any instances (to meet 
>> the exact_count) that don't exist, update any configuration deltas in those 
>> that do exist and then deploy any projects to those servers.
>>
>> I guess the bottom line question is simply, what's the appropriate 
>> strategy to make this work? Within that context, I do still need variables 
>> specific to each group/environment so the question I asked Arbab still 
>> stands. I really don't want to force developers to drop a ton of "extra 
>> vars" when the deploy. I'd like to keep that command line execution as dead 
>> simple as possible:
>>
>> # Run the deploy playbook against environment X
>> ansible-playbook -i staging deploy.yml
>>
>> I really do appreciate the help with this. Learning Ansible has been 
>> fairly simple, but figuring out how to organize for a non-trivial 
>> infrastructure has definitely been a challenge.
>>
>> On Sunday, October 25, 2015 at 2:50:21 AM UTC-4, Igor Cicimov wrote:
>>>
>>> Arbib is right, you will have to add them to a new group and use that in 
>>> the next play in the same playbook. I went overboard trying to simplify so 
>>> it does not confuse the beginner folk that might read this post.
>>>
>>> Anyway, the point is: in AWS the tags are very powerful in terms of 
>>> automation so tag everything and tag as much as possible and use that later 
>>> to your own advantage.
>>>
>>> On Sunday, October 25, 2015 at 12:31:29 PM UTC+11, Arbab Nazar wrote:
>>>>
>>>>  Excellent method but you cannot use dynamic inventory group Ansible 
>>>> creates based on Tags:
>>>>
>>>> - hosts: tag_Env_prod
>>>> ...
>>>>
>>>> - hosts: tag_Env_dev
>>>> ...
>>>>
>>>> - hosts: tag_Env_stage
>>>> ...
>>>>
>>>> in the same playbook because it will give the create that group doesn't 
>>>> exist or no host inside the group instead you can use the add_host module. 
>>>> Thanks 
>>>>
>>>

-- 
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/a6d39764-b176-4172-b1e1-fa12ce5a38c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to