title: Passing variables to ansible roles
body: <p>I have my directory structure as this</p>
  
  <pre><code>└── digitalocean
      ├── README.md
      ├── play.yml
      └── roles
          ├── bootstrap_server
          │   └── tasks
          │       └── main.yml
          ├── create_new_user
          │   └── tasks
          │       └── main.yml
          ├── update
          │   └── tasks
          │       └── main.yml
          └── vimserver
              ├── files
              │   └── vimrc_server
              └── tasks
                  └── main.yml
  </code></pre>
  
  <p>When I am creating a user under the role <code>create_new_user</code>, I was hard coding the user name as</p>
  
  <pre><code>---
  - name: Creating a user named username on the specified web server.
    user: 
      name: username
      state: present
      shell: /bin/bash
      groups: admin
      generate_ssh_key: yes
      ssh_key_bits: 2048
      ssh_key_file: .ssh/id_rsa
  
  - name: Copy .ssh/id_rsa from host box to the remote box for user username
    become: true
    copy: 
      src: ~/.ssh/id_rsa.pub
      dest: /home/usernmame/.ssh/authorized_keys
      mode: 0600
      owner: username
      group: username
  </code></pre>
  
  <p>One way of solving this may be to create a <code>var/main.yml</code> and put the username there. But I wanted something through which I can specify the username at <code>play.yml</code> level. As I am also using the username in the role <code>vimrcserver</code>. </p>
  
  <p>I am calling the roles using <code>play.yml</code></p>
  
  <pre><code>---
  - hosts: testdroplets
    roles:
      - update
      - bootstrap_server
      - create_new_user
      - vimserver
  </code></pre>
  
  <p>Would a template work here in this case? Couldn't find much from these <a href="https://stackoverflow.com/q/22077272/3834059">SO</a> <a href="https://stackoverflow.com/q/40404837/3834059">questions</a></p>