Answers: <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>
  
Answers: CC BY-SA 3.0
Answers: 2017-09-13T12:19:44.043Z
Answers: 2017-09-13T12:19:44.043Z
Answers: junkgui
Answers: <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>
  
Answers: CC BY-SA 3.0
Answers: 2017-09-12T16:06:16.747Z
Answers: 2017-09-12T16:06:16.747Z
Answers: Subrat Srivastwa
Body: <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>
  
Comments: CC BY-SA 3.0
Comments: 2017-09-11T19:35:11.220Z
Comments: 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.
Comments: 030
Comments: CC BY-SA 3.0
Comments: 2017-09-12T14:29:59.697Z
Comments: please post the output of `ls -lah /usr/local/etc/ansible/hosts` and also what user are you running ansible with?
Comments: 13dimitar
Comments: CC BY-SA 3.0
Comments: 2017-09-12T16:07:01.163Z
Comments: @030  thanks for the response it was helpful
Comments: Subrat Srivastwa
Tags: <ansible><amazon-ec2>
Title: How to create ansible host file on mac?
UserDisplayName: Subrat Srivastwa
ThreadText: # 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.
  
  
  ---
  
  