Hi all,


I am trying to set a new host fact (is_master, is_slave) based on 
comparison of a pre-assigned variable and ansible_hostname fact. 


group_vars/

    master_hostname: host1

    slave_hostname: host2



Tasks

- name: Set master host fact

  set_fact:

     is_master: yes

  when: master_hostname == ansible_hostname


- name: Set slave host fact

  set_fact:

     is_slave: yes

  when: slave_hostname == ansible_hostname


- name: copy master configuration file

  template:

     src: master.j2

     dest: /etc/master.conf

  when: is_master == True


- name: copy slave configuration file

  template:

     src: slave.j2

    dest: /etc/slave.conf

  when: is_slave == True


TASK [Gathering Facts] 
*********************************************************

ok: [host1]

ok: [host2]


TASK [Set is_master variable] ***************************************

ok: [host1]

skipping: [host1]


TASK [Set is_slave variable] ****************************************

skipping: [host2]

ok: [host2]


The goal I am trying to reach is to run certain tasks depending whether the 
host is master or slave. But these set_fact tasks always get skipped even 
though condition should be true. Really appreciate your help in pointing 
out what I am doing wrong.

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/b4039197-4934-4bc4-94ef-40996b6fde06%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to