<p>Run:</p>

<pre><code>$ sudo touch /usr/local/etc/ansible/hosts
$ sudo vi /usr/local/etc/ansible/hosts
</code></pre>

<p>To create a file and then open it.</p>

CC BY-SA 3.0
2017-09-13T12:19:44.043Z
2017-09-13T12:19:44.043Z
junkgui
<p>The issue was that the host file did not exist. So, first I created the host file at the location: /usr/local/etc/ansible/hosts
Then after that i could add the hosts to this file.</p>

CC BY-SA 3.0
2017-09-12T16:06:16.747Z
2017-09-12T16:06:16.747Z
Subrat Srivastwa
<p>When I try to create ansible host file as follows: </p>

<pre><code>sudo vi /usr/local/etc/ansible/hosts
</code></pre>

<p>When I try to save the file I get following error:</p>

<pre><code>"/usr/local/etc/ansible/hosts" E212: Can't open file for writing
</code></pre>

CC BY-SA 3.0
2017-09-11T19:35:11.220Z
That error could be thrown if the file does not exists. According to [this](https://stackoverflow.com/questions/21958727/where-to-store-ansible-host-file-on-mac-os-x) and [this](http://docs.ansible.com/ansible/latest/intro_inventory.html) source the path to the hosts file is different.
030
CC BY-SA 3.0
2017-09-12T14:29:59.697Z
please post the output of `ls -lah /usr/local/etc/ansible/hosts` and also what user are you running ansible with?
13dimitar
CC BY-SA 3.0
2017-09-12T16:07:01.163Z
@030  thanks for the response it was helpful
Subrat Srivastwa
<ansible><amazon-ec2>
How to create ansible host file on mac?
Subrat Srivastwa
# How to create ansible host file on mac?

(Asked by: username_0 on 2017-09-11)

When I try to create ansible host file as follows: 
sudo vi /usr/local/etc/ansible/hosts

When I try to save the file I get following error:
"/usr/local/etc/ansible/hosts" E212: Can't open file for writing

**Tags:** ansible, amazon-ec2

> **Comments:**
> **username_1**: That error could be thrown if the file does not exists. According to [this](https://stackoverflow.com/questions/21958727/where-to-store-ansible-host-file-on-mac-os-x) and [this](http://docs.ansible.com/ansible/latest/intro_inventory.html) source the path to the hosts file is different.  
> **username_2**: please post the output of `ls -lah /usr/local/etc/ansible/hosts` and also what user are you running ansible with?  
> **username_0**: @username_1  thanks for the response it was helpful  

---

## 2 answers

### Answer by username_3 on 2017-09-13. Score: 3

Run:
$ sudo touch /usr/local/etc/ansible/hosts
$ sudo vi /usr/local/etc/ansible/hosts

To create a file and then open it.


---

### Answer by username_0 on 2017-09-12. Score: 0

The issue was that the host file did not exist. So, first I created the host file at the location: /usr/local/etc/ansible/hosts
Then after that i could add the hosts to this file.


---

