Re: [ansible-project] How to structure variables to distinguish different environments

2020-07-07 Thread Xinhuan Zheng
Hello,

That construct actually makes sense to me. The fact of Development vs. 
Production is controlled by their network. We can just create custom fact 
based on each host IP address, and return customer fact variable. Then we 
can set nfs_server per that custom fact.

Thanks for showing this tip.

- Xinhuan

On Thursday, July 2, 2020 at 6:23:27 AM UTC-4, Srinivas Naram wrote:
>
> There could be some distinction between both the environments. Can you use 
> gather_facts and get the differentiating value ?
>
> if you are able to get it using gather_facts, you can use set_facts
>
> Example
>
> set_facts:
>nfs_server: xyx
> when: ansible_distribution= 'CentOS'
>
> set_fact:
>nfs_server: abc
> when: ansible_distribution ='Ubuntu'
>
> On Thu, Jul 2, 2020 at 12:26 AM Xinhuan Zheng  > wrote:
>
>> Hello,
>>
>> I want to define a variable for playbook in *group_vars/server_genre* 
>> file. However, I don't know if Ansible can support something like 
>> server_genre@environment syntax notation. Here is the detail:
>>
>> *In inventory/environment*:
>> ---
>> [server_genre]
>> myserver1.example.com
>>
>> *In group_vars/server_genre:*
>> ---
>> nfs_server: mynfsserver1.example.com
>>
>> *In server_genre.yml playbook:*
>> ---
>> - name: Playbook for server_genre
>>   hosts: server_genre
>>   gather_facts: yes
>>
>>   tasks:
>>
>>   - name: Install Nfs client
>> package:
>>   name: nfs-utils
>>   state: present
>>   - name: mount nfs
>> mount:
>>   path: /mymount
>>   src: "{{ nfs_server }}"
>>   fstype: nfs
>>   opts: ro
>>   state: mounted
>>
>> In a different environment, the variable {{ nfs_server }} will have 
>> different value, however, I can't separate the different values using one 
>> single group_var/server_genre file, unless Ansible supports something like 
>> group_vars/server_genre@enviornment.
>>
>> How do I accomplish the variable value distinction in my case?
>>
>> Thanks,
>>
>> - Xinhuan
>>
>>
>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/96edc459-2fec-4626-b7ac-2dae6d330505o%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/9bbe8409-2805-442d-af8c-f092195a8f89o%40googlegroups.com.


Re: [ansible-project] How to structure variables to distinguish different environments

2020-07-02 Thread Srinivas Naram
There could be some distinction between both the environments. Can you use
gather_facts and get the differentiating value ?

if you are able to get it using gather_facts, you can use set_facts

Example

set_facts:
   nfs_server: xyx
when: ansible_distribution= 'CentOS'

set_fact:
   nfs_server: abc
when: ansible_distribution ='Ubuntu'

On Thu, Jul 2, 2020 at 12:26 AM Xinhuan Zheng 
wrote:

> Hello,
>
> I want to define a variable for playbook in *group_vars/server_genre*
> file. However, I don't know if Ansible can support something like
> server_genre@environment syntax notation. Here is the detail:
>
> *In inventory/environment*:
> ---
> [server_genre]
> myserver1.example.com
>
> *In group_vars/server_genre:*
> ---
> nfs_server: mynfsserver1.example.com
>
> *In server_genre.yml playbook:*
> ---
> - name: Playbook for server_genre
>   hosts: server_genre
>   gather_facts: yes
>
>   tasks:
>
>   - name: Install Nfs client
> package:
>   name: nfs-utils
>   state: present
>   - name: mount nfs
> mount:
>   path: /mymount
>   src: "{{ nfs_server }}"
>   fstype: nfs
>   opts: ro
>   state: mounted
>
> In a different environment, the variable {{ nfs_server }} will have
> different value, however, I can't separate the different values using one
> single group_var/server_genre file, unless Ansible supports something like
> group_vars/server_genre@enviornment.
>
> How do I accomplish the variable value distinction in my case?
>
> Thanks,
>
> - Xinhuan
>
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/96edc459-2fec-4626-b7ac-2dae6d330505o%40googlegroups.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAG-N3P5BygF3JiJAa6LXsMJ4798w6kH5OtVYJtRg5U-7uHnQog%40mail.gmail.com.