gpt4 book ai didi

ssh - "Could not resolve hostname"Ansible

转载 作者:行者123 更新时间:2023-12-02 13:47:01 26 4
gpt4 key购买 nike

我根据 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 的新手,所以我将非常感谢您的帮助!

最佳答案

好的,所以 Ansible list 可以基于以下格式:

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

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

    Example


    # 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

    Grouping of hosts will only end when the end of file or another group detected. So if you wish to have hosts that don't belong to a group, make sure they're defined above the group definition.



    IE。上例中的所有内容都属于 test-group ,如果你遵循;它将在所有主机上执行:
    ansible test-group -u ubuntu -m ping

    关于ssh - "Could not resolve hostname"Ansible,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47616861/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com