title: Dynamically assign master/slave variables in Ansible role
body: <p>I have a simple mariadb role which permits to setup master/slave replication on two servers. In order to do this, I have to define in my inventory my 2 nodes like this:</p>
  
  <pre><code>node1 master=true 
  node2 slave=true 
  </code></pre>
  
  <p>This way, I can setup one role to setup master/slave replication using Ansible when statement playing with this vars.</p>
  
  <pre><code>- name: Setup master conf
    template: &gt;-
      src="templates/master.conf.j2"
      dest="{{ master_config_file }}"
    when:
      - master is defined
  </code></pre>
  
  <p>Now, I would like to get something more automatic that could dynamically and randomly assign a master variable to one node, and slave variable to all other nodes.</p>
  
  <p>I have seen some Ansible doc about variables and filters, but none of them seems to be adapted to that. I guess that I have to develop my own Ansible variable plugin to do that. </p>