Answers: <p>There are a few GitHub repos regarding Ansible best practices, and I've found <a href="https://github.com/enginyoyen/ansible-best-practises" rel="nofollow noreferrer">enginyoyen/ansible-best-practices</a> helpful not only in your case but also to understand the playbook/inventory/role/task differences in a full-blown Ansible project. </p>
  
  <p>Some highlights: (<code>/</code> refers to the <strong>project's</strong> home directory)</p>
  
  <ul>
  <li>Your variables do indeed go in <code>/group_vars/</code>
  
  <ul>
  <li><code>/group_vars/windows.yml</code> will be automatically read by hosts you assign to the windows <strong>group</strong> </li>
  <li><code>/group_vars/db.yml</code> will be automatically read by hosts you assign to the db <strong>group</strong> and so on</li>
  </ul></li>
  <li>You may also include files with names like <code>/host_vars/win_host_1.yml</code> which will be read only by that host </li>
  <li><p>The groups from <code>/group_vars/</code> are defined in your inventory file<strong>s</strong> (plural)</p>
  
  <pre><code>[windows]
  win_host1.example.com
  win_host_2.example.com
  </code></pre></li>
  <li><p>Inventory files have names like <code>/production.yml</code> and <code>/staging.yml</code> to help ensure code in different states of readiness is deployed to (ideally) identical environments.</p></li>
  </ul>
  
  <p>Other highlights not directly answering your question</p>
  
  <ul>
  <li>A <em>role</em> is a file made of the <em>tasks</em> required to do something, like install <code>nginx</code>. They have names like <code>/roles/install_nginx.yml</code></li>
  <li>Playbooks have names like <code>/playbooks/win_hosts.yml</code> which do nothing but match the <em>groups</em> from your inventory files with the <em>roles</em> you want hosts in those groups to run. </li>
  <li><strong>When you run <code>ansible-playbook</code> your <code>$HOME</code> should be  <code>/playbooks/</code></strong> so that the different inventory files are referred as <code>ansible-playbook -i ../production.yml win_hosts.yml</code></li>
  <li>This is also the place to put a custom ansible config file, <code>/playbooks/ansible.cfg</code></li>
  <li>There's also a way to manage <em>external</em> roles from Ansible Galaxy or GitHub and keep them separate from custom roles you built, but still in your project directory instead of <code>/etc/ansible/roles/</code> where <code>ansible-galaxy</code> puts them by default.</li>
  <li>A nice little bash script to install Ansible </li>
  </ul>
  
Answers: CC BY-SA 3.0
Answers: 2017-09-16T01:14:26.677Z
Answers: 2017-09-16T01:14:26.677Z
Answers: Stephen C
Answers: <p>There are two places where Ansible looks for <code>group_vars</code> subdirectory:</p>
  
  <ul>
  <li>the playbook directory - the one containing a playbook you run</li>
  <li>the inventory directory - the one specified with <code>-i</code> option at run time, or a default one (usually <code>/etc/ansible</code>, or <code>/usr/local/etc/ansible</code>)</li>
  </ul>
  
  <p>In most typical scenario you might place <code>group_vars</code> along with the <code>playbook.yml</code>.</p>
  
  <p>The example you posted uses the second method, so to reference the files you need to add <code>-i</code> to the command:</p>
  
  <pre><code>ansible windows -m ping -i ./windows
  </code></pre>
  
Answers: CC BY-SA 3.0
Answers: 2017-05-30T17:55:28.253Z
Answers: thanks for this response.  It fits the bill for my specific question so marking as answer.  This link also has the definitive answer regarding variable processing for those interested!  http://docs.ansible.com/ansible/intro_inventory.html#group-variables
Answers: A L
Answers: CC BY-SA 3.0
Answers: 2017-05-25T07:40:03.717Z
Answers: 2017-05-25T07:45:46.680Z
Answers: 2017-05-25T07:45:46.680Z
Answers: techraf
Body: <p>I'm trying to simply connect to a machine and run the win_ping module.</p>
  
  <p>There are several tutorials online that outline a few key steps:</p>
  
  <ul>
  <li>Create a directory <code>./windows</code></li>
  <li>Create a file <code>hosts</code> in <code>./windows</code></li>
  <li>Create a directory <code>./windows/group_vars</code></li>
  <li>Create a file <code>windows.yml</code> in <code>./windows/group_vars</code></li>
  <li>Insert several variables with your Windows credentials into <code>windows.yml</code></li>
  </ul>
  
  <p>The problem is that none of these actually specify where to put these relative to the '.'.  I've tried placing this structure in <code>/etc/ansible/</code> and unfortunately it's looking like Ansible isn't picking this up at all.  I've also tried moving the structure around but no luck.</p>
  
  <p>How do I get Ansible to reference the directory I've created?  I believe <code>ansible.cfg</code> would make sense but I can only see how to point it to a default inventory file. Interestingly enough - even adding a group called 'windows' in the base hosts file and calling ansible with the group there - it says no hosts found. I have also uncommented the inventory location in ansible.cfg to point to <code>/etc/ansible/hosts</code> and it still says no hosts found when calling <code>ansible windows -m ping</code> (or <code>win_ping</code> for that matter).</p>
  
Tags: <ansible>
Title: Connecting to a Windows machine with Ansible
UserDisplayName: A L
ThreadText: # Connecting to a Windows machine with Ansible
  
  (Asked by: username_0 on 2017-05-25)
  
  I'm trying to simply connect to a machine and run the win\_ping module.
  
  There are several tutorials online that outline a few key steps:
  
  * Create a directory `./windows`
  * Create a file `hosts` in `./windows`
  * Create a directory `./windows/group_vars`
  * Create a file `windows.yml` in `./windows/group_vars`
  * Insert several variables with your Windows credentials into `windows.yml`
  
  The problem is that none of these actually specify where to put these relative to the '.'. I've tried placing this structure in `/etc/ansible/` and unfortunately it's looking like Ansible isn't picking this up at all. I've also tried moving the structure around but no luck.
  
  How do I get Ansible to reference the directory I've created? I believe `ansible.cfg` would make sense but I can only see how to point it to a default inventory file. Interestingly enough - even adding a group called 'windows' in the base hosts file and calling ansible with the group there - it says no hosts found. I have also uncommented the inventory location in ansible.cfg to point to `/etc/ansible/hosts` and it still says no hosts found when calling `ansible windows -m ping` (or `win_ping` for that matter).
  
  **Tags:** ansible
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2017-05-25. Score: 5 | Accepted answer
  
  There are two places where Ansible looks for `group_vars` subdirectory:
  
  * the playbook directory - the one containing a playbook you run
  * the inventory directory - the one specified with `-i` option at run time, or a default one (usually `/etc/ansible`, or `/usr/local/etc/ansible`)
  
  In most typical scenario you might place `group_vars` along with the `playbook.yml`.
  
  The example you posted uses the second method, so to reference the files you need to add `-i` to the command:
  
  ```
  ansible windows -m ping -i ./windows
  
  ```
  
  > **Comments:**
  > **username_0**: thanks for this response.  It fits the bill for my specific question so marking as answer.  This link also has the definitive answer regarding variable processing for those interested!  http://docs.ansible.com/ansible/intro_inventory.html#group-variables  
  
  ---
  
  ### Answer by username_1 on 2017-09-16. Score: 0
  
  There are a few GitHub repos regarding Ansible best practices, and I've found [enginyoyen/ansible-best-practices](https://github.com/enginyoyen/ansible-best-practises) helpful not only in your case but also to understand the playbook/inventory/role/task differences in a full-blown Ansible project.
  
  Some highlights: (`/` refers to the **project's** home directory)
  
  * Your variables do indeed go in `/group_vars/`
    + `/group_vars/windows.yml` will be automatically read by hosts you assign to the windows **group**
    + `/group_vars/db.yml` will be automatically read by hosts you assign to the db **group** and so on
  * You may also include files with names like `/host_vars/win_host_1.yml` which will be read only by that host
  * The groups from `/group_vars/` are defined in your inventory file**s** (plural)
  
    ```
    [windows]
    win_host1.example.com
    win_host_2.example.com
  
    ```
  * Inventory files have names like `/production.yml` and `/staging.yml` to help ensure code in different states of readiness is deployed to (ideally) identical environments.
  
  Other highlights not directly answering your question
  
  * A *role* is a file made of the *tasks* required to do something, like install `nginx`. They have names like `/roles/install_nginx.yml`
  * Playbooks have names like `/playbooks/win_hosts.yml` which do nothing but match the *groups* from your inventory files with the *roles* you want hosts in those groups to run.
  * **When you run `ansible-playbook` your `$HOME` should be `/playbooks/`** so that the different inventory files are referred as `ansible-playbook -i ../production.yml win_hosts.yml`
  * This is also the place to put a custom ansible config file, `/playbooks/ansible.cfg`
  * There's also a way to manage *external* roles from Ansible Galaxy or GitHub and keep them separate from custom roles you built, but still in your project directory instead of `/etc/ansible/roles/` where `ansible-galaxy` puts them by default.
  * A nice little bash script to install Ansible
  
  
  ---
  
  