AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 458475
Accepted
grimmjow_sms
grimmjow_sms
Asked: 2018-07-26 14:11:13 +0800 CST2018-07-26 14:11:13 +0800 CST 2018-07-26 14:11:13 +0800 CST

Ansible:如何解析库存来源

  • 772

我正在关注我从 Packt 获得的 Ansible 教程,我已经创建了 3 个 Ubuntu 容器 (lxc) 并让它们启动并运行。我也可以登录到他们每个人。

我已经通过以下方式下载了 Ansible:git clone ansible-git-url然后获取了它。

我的工作设置如下: /home/myuser/code在这里我有 2 个文件夹:(ansible整个 git repo)ansible_course,我有 2 个文件:ansible.cfg和inventory.

inventory包含以下内容:

[allservers]
192.168.122.117 
192.168.122.146
192.168.122.14

[web]
192.168.122.146
192.168.122.14

[database]
192.168.122.117

并ansible.cfg包含:

[root@localhost ansible_course]# cat ansible.cfg
[defaults]
host_key_checking = False

然后从这条路径:/home/myuser/code/ansible_course我尝试执行以下操作:

$ ansible 192.168.122.117 -m ping -u root

教程中的那个人就是这样做的,他从 获得了成功响应ping,但我收到以下错误消息:

[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
[WARNING]: Could not match supplied host pattern, ignoring: 192.168.122.117

在教程中,他从未说过我需要做一些特别的事情来提供inventory源代码,他只是说我们需要使用inventory我们拥有的 Linux 容器的 IP 地址创建一个文件。

我的意思是,他没有说我们需要执行命令来设置它。

ansible lxc
  • 2 2 个回答
  • 30897 Views

2 个回答

  • Voted
  1. Best Answer
    thrig
    2018-07-26T14:18:12+08:002018-07-26T14:18:12+08:00

    您可能想告诉 ansible 主机文件在哪里ansible.cfg,例如

    [defaults]
    inventory=inventory
    

    假设inventory实际上是您的库存文件。

    • 11
  2. slm
    2018-07-26T19:03:26+08:002018-07-26T19:03:26+08:00

    背景

    ansible您可以依赖ansible.cfg文件来指定文件的名称,也inventory可以像这样手动指定它:

    明确告知
    $ ansible -i inventory -m ping -u root 192.168.122.117
    
    通过 ansible.cfg 隐式告知
    $ ansible -m ping -u root 192.168.122.117
    

    显式

    对于您明确告知ansible要使用哪个清单文件的方法,该用法显示了以下描述:

    从ansible用法上看:

     -i INVENTORY, --inventory=INVENTORY
              specify inventory host path or comma separated host list.
    

    隐式

    对于隐式方法,您必须更精通 Ansible 才能意识到它是这样工作的。您可以使用ansible's 详细模式来查看更多默认情况下正在执行的操作:

    $ ansible -vvv -m ping -u root box-101
    ...
    ...
    config file = /Users/user1/somedir/ansible.cfg
    ...
    ...
    Using /Users/user1/somedir/ansible.cfg as config file
    Parsed /Users/user1/somedir/inventory inventory source with ini plugin
    META: ran handlers
    Using module file /Users/user1/projects/git_repos/ansible/lib/ansible/modules/system/ping.py
    ...
    ...
    box-101 | SUCCESS => {
        "changed": false,
        "invocation": {
            "module_args": {
                "data": "pong"
            }
        },
        "ping": "pong"
    }
    ...
    ...
    

    在上面我正在ping box-101。您可以看到这些行显示ansible.cfg正在使用哪个文件:

    config file = /Users/user1/somedir/ansible.cfg
    Using /Users/user1/ansible.cfg as config file
    

    并通过这个ansible.cfg文件最终清点哪些:

    Parsed /Users/user1/somedir/inventory inventory source with ini plugin
    

    正是这些选项将 ansible 指向inventory文件:

    $ cat ansible.cfg
    ...
    [defaults]
    inventory      = inventory
    ...
    
    • 5

相关问题

  • sshpass 在 alpine linux 中不起作用

  • Ansible shell 模块空响应

  • 使用 LXC 2.x 将主机文件夹挂载到来宾,但它是只读的吗?

  • 无法在 Alpine Linux LXC 上启动 NFS 服务器

  • LXC 容器内部从零开始的 Linux

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    ssh 无法协商:“找不到匹配的密码”,正在拒绝 cbc

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    如何卸载内核模块“nvidia-drm”?

    • 13 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Wong Jia Hau ssh-add 返回:“连接代理时出错:没有这样的文件或目录” 2018-08-24 23:28:13 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST
  • Martin Hope
    Bagas Sanjaya 为什么 Linux 使用 LF 作为换行符? 2017-12-20 05:48:21 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve