在M上安装后找不到ansible.cfg

2024-06-26 12:35:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我的应用程序安装ansible==2.2.1.0作为其要求的一部分,我希望它使用我在特定位置拥有的库。 我试图找到ansible.cfg文件,但在任何地方都找不到,也不确定最好放在哪里。 我在用Mac操作系统。 编辑: 我在:/Users/<myuser>/.ansible.cfg设置了一个配置文件,当我用-vvv运行ansible-playbook时,它显示: 使用/Users/<myuser>/.ansible.cfg作为配置文件

但我收到这些错误和警告是有原因的:

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

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

ERROR! conflicting action statements

谢谢!


Tags: 文件编辑ismac配置文件地方ansiblecfg
1条回答
网友
1楼 · 发布于 2024-06-26 12:35:41

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

也就是说,这些位置不需要填充就可以运行。但你应该在那里寻找它们。

如果您的应用程序正在运行Ansible,并且您希望指定配置的内容,那么只需在执行目录中创建一个ansible.cfg。如果您希望管理配置,只需按此顺序查找它们并根据需要进行管理。您甚至可以创建每个文件,然后Ansible将查找它们。然后,您可以通过将-vv参数添加到ansibleansible-playbook调用来确定正在使用哪个ansible.cfg

您看到的警告和错误与未找到的Ansible配置无关。

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

当您调用ansibleansible-playbook时,添加--inventory path/to/your/inventory。这也将解决下面的警告。

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

ERROR! conflicting action statements

这通常是由在单个任务项中有多个模块调用引起的。把他们分开:

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

应该是

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

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

相关问题 更多 >