大网数据广告活动
服务器运维问答

Ansible ignores it's configuration file (ansible.cfg), what could be the reason?

· 52CE 我爱测

I'm running Vagrant 1.8.1 and ansible 1.8.4 on Mac OS. I've started 2 Ubuntu machines on vagrant: itais-MacBook-Pro:ansible-dir itaiganot$ ./dev/hosts --list | jq '.' { "web": [ "web" ], "app": [ "app-1" ], "vagrant": [ "web", "a…

问题原文

原帖链接 · Itai Ganot · CC BY-SA 3.0

I'm running Vagrant 1.8.1 and ansible 1.8.4 on Mac OS.

I've started 2 Ubuntu machines on vagrant:

itais-MacBook-Pro:ansible-dir itaiganot$ ./dev/hosts --list | jq '.'
{
  "web": [
    "web"
  ],
  "app": [
    "app-1"
  ],
  "vagrant": [
    "web",
    "app-1"
  ],
  "_meta": {
    "hostvars": {
      "web": {
        "ansible_ssh_host": "127.0.0.1",
        "ansible_ssh_port": "2201",
        "ansible_ssh_user": "vagrant",
        "ansible_ssh_private_key_file": "/Users/itaiganot/ansible-dir/.vagrant/machines/web/virtualbox/private_key"
      },
      "app-1": {
        "ansible_ssh_host": "127.0.0.1",
        "ansible_ssh_port": "2202",
        "ansible_ssh_user": "vagrant",
        "ansible_ssh_private_key_file": "/Users/itaiganot/ansible-dir/.vagrant/machines/app-1/virtualbox/private_key"
      }
    }
  }
}

I have an ansible.cfg file in the current directory where the VagrantFile also resides.

itais-MacBook-Pro:ansible-dir itaiganot$ cat ansible.cfg
[defaults]
host_key_checking = False
inventory = dev

in the dev directory there are two files: hosts - which is a python script which automatically finds the IP of the booted vagrant machines and another file which includes the roles configurations:

itais-MacBook-Pro:dev itaiganot$ cat static
[web]
[app]

[role_web:children]
web

[role_app:children]
app

I'm trying to run the following command: ansible role_app -a 'hostname'

But i'm getting the following error:

ERROR: Unable to find an inventory file, specify one with -i ?

I've googled it and found that I can export a variable to point to the config, like so:

export ANSIBLE_CONFIG=/Users/itaiganot/ansible-dir/ansible.cfg

But that didn't help me as well.

By the way, adding the dev directory as inventory to the command works:

itais-MacBook-Pro:ansible-dir itaiganot$ ansible role_app -a 'hostname' -i dev
app-1 | success | rc=0 >>
app-1

Any idea why the ansible.cfg file is ignored by ansible?

已采纳解答

原帖链接 · Diamond · CC BY-SA 3.0

According to Ansible doc: http://docs.ansible.com/ansible/intro_configuration.html#inventory, this variable is not availabe before version 1.9:

inventory

This is the default location of the inventory file, script, or directory that Ansible will use to determine what hosts it has available to talk to:

inventory = /etc/ansible/hosts

It used to be called hostfile in Ansible before 1.9

Another thing would be to make sure that there is not another ansible.cfg file available in the system:http://docs.ansible.com/ansible/intro_configuration.html

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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-03-30)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。