Pavel Zagalsky
Pavel Zagalsky

Reputation: 1636

Cannot find ansible.cfg after installation on Mac OS

My app installs ansible==2.2.1.0 as part of its requirements and I'd like it to use a library I have in a specific location. I try to find the ansible.cfg file but can't find it anywhere and not sure where it's best to be put. I am using Mac OS. EDIT: I set up a config file at: /Users/<myuser>/.ansible.cfg and when I run the ansible-playbook with -vvv it shows: Using /Users/<myuser>/.ansible.cfg as config file

But I am getting this errors and warnings for some reason:

[WARNING]: Host file not found: /etc/ansible/hosts

[WARNING]: provided hosts list is empty, only localhost is available

ERROR! conflicting action statements

Thanks!

Upvotes: 2

Views: 17354

Answers (1)

Schlueter
Schlueter

Reputation: 4029

From the Ansible docs:

Changes can be made and used in a configuration file which will be processed in the following order:

  • ANSIBLE_CONFIG (an environment variable)
  • ansible.cfg (in the current directory)
  • .ansible.cfg (in the home directory)
  • /etc/ansible/ansible.cfg

That said, these locations need not be populated for Ansible to function. But you should look for them there.

If your application is running Ansible, and you would like to specify the contents of the config, just create an ansible.cfg in the executing directory. If you are looking to manage the config, just look for them in that order and manage as you see fit. You could even create each of those files and Ansible will look for them. You may then determine which ansible.cfg is being used by adding the -vv argument to your ansible or ansible-playbook calls.

The warnings and errors you are seeing are unrelated to the Ansible config not being found.

[WARNING]: Host file not found: /etc/ansible/hosts

When you call ansible or ansible-playbook, add --inventory path/to/your/inventory. This will also resolve the warning below.

[WARNING]: provided hosts list is empty, only localhost is available

ERROR! conflicting action statements

This is typically caused by having multiple module calls within a single task item. Just split them up:

- name: make some files
  file: state=directory dest=/etc/foo
  file: src=foo/bar dest=/etc/foo/bar

Should be

- name: create a dir
  file: state=directory dest=/etc/foo

- name: create a file
  file: src=foo/bar dest=/etc/foo/bar

Upvotes: 3

Related Questions