【问题标题】:"Could not resolve hostname" Ansible“无法解析主机名” Ansible
【发布时间】:2017-12-03 09:02:30
【问题描述】:

我根据this tutorial创建了我的第一个ansible playbook,所以看起来是这样的:

---
- hosts: hostb
  tasks:
      - name: Create file
        file:
            path: /tmp/yallo
            state: touch

- hosts: my_hosts
  sudo: yes
  tasks:
      - name: Create user
        user:
            name: mario
            shell: /bin/zsh

      - name: Install zlib
        yum:
            name: zlib
            state: latest

但是,我不知道应该将哪些主机放入主机文件中。我现在有这样的东西:

[my_hosts]
hostA
hostB

显然,它不起作用,我明白了:

ssh: Could not resolve hostname hostb: Name or service not known

那么我应该如何更改我的主机文件?我是 ansible 的新手,因此非常感谢您的帮助!

【问题讨论】:

  • 我知道,但是在本教程中,只有一个名称,我不知道应该有哪些 IP 地址。
  • 如果您觉得不清楚,请联系博客作者。页面底部有一个评论表格。 StackOverflow 不是辅导网站;这与编程无关,正如我已经提到的,除了你之外没有人知道如何访问你的机器。

标签: ssh ansible ubuntu-14.04


【解决方案1】:

好的,因此 Ansible 清单可以基于以下格式:

  • 主机名 => IP Address
  • 主机名 => DHCP or Hosts file hostname reference localhost/cassie.local
  • 创建自己的别名 => hostname ansible_host=IP Address
  • 主机组 => [group_name]

这是你可以使用的最基本的结构。

例子

# Grouping
[test-group]

# IP reference
192.168.1.3

# Local hosts file reference
localhost

# Create your own alias
test ansible_host=192.168.1.4

# Create your alias with port and user to login as
test-2 ansible_host=192.168.1.5 ansible_port=1234 ansible_user=ubuntu

只有在检测到文件结尾或另一个组时,主机分组才会结束。因此,如果您希望拥有不属于某个组的主机,请确保将它们定义在组定义之上。

I.E.上述示例中的所有内容都属于test-group,如果您执行以下操作;它将在所有主机上执行:

ansible test-group -u ubuntu -m ping


【讨论】:

    【解决方案2】:

    ansible 在您的清单文件中是区分大小写的主机名是 hostB 而在您的剧本中是 hostb 我认为它显示“名称或服务未知”错误的方式

    将 playbook 中的主机名更改为 hostB

    【讨论】:

      猜你喜欢
      • 2020-11-13
      • 2017-03-26
      • 2013-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-13
      • 1970-01-01
      相关资源
      最近更新 更多