On 4/17/20 4:54 PM, Baptiste Doublet wrote:
> Hi,
> 
> That did the job:
> etcd_cluster: # recommendation: 3 or 5-7 nodes
>       hosts:
>         demo_postgres1:
>             etcd_ip: '***'
> 
> I don't know why I used vars, maybe because I read a lot of ansible 
> documentation like How to build your inventory and
> that cursed my brain ^^
> 

While the documentation covers a lot of good thing, it doesn't note the 
differences between group variables (with vars:
) and host vars (without vars:).

In order to avoid confusion, you can use separate files for the host variables.

Regards
         Racke

> atlanta:
>   hosts:
>     host1:
>     host2:
>   vars:
>     ntp_server: ntp.atlanta.example.com
>     proxy: proxy.atlanta.example.com
> 
> 
> Thanks again Racke !
> 
> Le mardi 14 avril 2020 11:39:36 UTC+2, Baptiste Doublet a écrit :
> 
>     Hi Everybody,
> 
>     I have a problem that I can't resolve on my own.
>     I want to deploy an etcd cluster with postgresql on the same servers
>     I have three servers and this is my inventory file:
> 
>     ```
>     all:
>     children:
>     etcd_cluster: # recommendation: 3 or 5-7 nodes
>     hosts:
>     demo_postgres1:
>     vars:
>     etcd_ip: '***'
>     demo_postgres2:
>     vars:
>     etcd_ip: '***'
>     demo_postgres3:
>     vars:
>     etcd_ip: '***'
>     master:
>     hosts:
>     demo_postgres1:
>     vars:
>     postgres_ip: '***'
>     postgresql_exists: 'false'
>     replica:
>     hosts:
>     demo_postgres2:
>     vars:
>     postgres_ip: '***'
>     postgresql_exists: 'false'
>     demo_postgres3:
>     vars:
>     postgres_ip: '***'
>     postgresql_exists: 'false'
>     balancers:
>     hosts:
>     demo_haproxy1:
>     vars:
>     haproxy_ip: '***'
>     demo_haproxy2:
>     vars:
>     haproxy_ip: '***'
>     demo:
>     vars:
>     ansible_ssh_common_args: "-F ../../ssh_config/demo_config"
>     children:
>     balancers:
>     etcd_cluster:
>     postgres_cluster:
>     children:
>     master:
>     replica:
>     ```
>     I have the demo_postgres[0-3] servers that run etcd and postgres. Just to 
> prepare an external instance for etcd
>     cluster, I have separated its in two distinct groups: etcd_cluster and 
> postgres_cluster.
>     I have etcd_ip vars and postgres_ip varsrespectivelyon these groups.
> 
>     My problem is when I run my playbook with hosts: etcd_cluster and I print 
> hostvars, I get the hostvars of
>     postgres_cluster:
> 
>     ```
>     PLAY [etcd_cluster]
>     
> ***************************************************************************************************************************************************************************
> 
>     TASK [Gathering Facts]
>     
> ************************************************************************************************************************************************************************
>     ok: [demo_postgres1]
>     ok: [demo_postgres3]
>     ok: [demo_postgres2]
> 
>     TASK [Ansible | List all known variables and facts]
>     
> *******************************************************************************************************************************************
>     ok: [demo_postgres1] => {
>         "hostvars[inventory_hostname]['vars']": {
>             "postgres_ip": "***",
>             "postgresql_exists": "false"
>         }
>     }
>     ok: [demo_postgres2] => {
>         "hostvars[inventory_hostname]['vars']": {
>             "postgres_ip": "***",
>             "postgresql_exists": "false"
>         }
>     }
>     ok: [demo_postgres3] => {
>         "hostvars[inventory_hostname]['vars']": {
>             "postgres_ip": "***",
>             "postgresql_exists": "false"
>         }
>     }
> 
>     ```
>     I didn't find any information about the merging of hostvars when the host 
> is in multiple groups and when I have
>     tested to remove the postgres_cluster group, I get the correct hostvars:
> 
>     ```
>     PLAY [etcd_cluster]
>     
> ***************************************************************************************************************************************************************************
> 
>     TASK [Gathering Facts]
>     
> ************************************************************************************************************************************************************************
>     ok: [demo_postgres1]
>     ok: [demo_postgres3]
>     ok: [demo_postgres2]
> 
>     TASK [Ansible | List all known variables and facts]
>     
> *******************************************************************************************************************************************
>     ok: [demo_postgres1] => {
>         "hostvars[inventory_hostname]['vars']": {
>             "etcd_ip": "***"
>         }
>     }
>     ok: [demo_postgres2] => {
>         "hostvars[inventory_hostname]['vars']": {
>             "etcd_ip": "***"
>         }
>     }
>     ok: [demo_postgres3] => {
>         "hostvars[inventory_hostname]['vars']": {
>             "etcd_ip": "***"
>         }
>     }
>     ```
> 
>     I would expect that my etcd_ip was merged with postgres_ip ? I can 
> resolve this by adding the etcd_ip in
>     postgres_cluster hostvars but I want to understand why merge is not 
> working.
> 
>     If you need more information, feel free to ask.
> 
>     Best regards,
> 
>     BDO
> 
> -- 
> 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
> [email protected] 
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/c455f9f0-ff4a-4d15-b7c1-d0f9ff06bc37%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/c455f9f0-ff4a-4d15-b7c1-d0f9ff06bc37%40googlegroups.com?utm_medium=email&utm_source=footer>.


-- 
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/40ae18a4-aa2e-c6dc-63e7-2a2108406df2%40linuxia.de.

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to