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
    • 最新
    • 标签
主页 / server / 问题 / 1068201
Accepted
Hiddai
Hiddai
Asked: 2021-06-30 12:22:25 +0800 CST2021-06-30 12:22:25 +0800 CST 2021-06-30 12:22:25 +0800 CST

如何使用清单和 group_vars 文件对主机进行 win_ping 操作?

  • 772
  • 我正在尝试编写一个正确的命令行,它将 ping 到我的清单文件中详细说明的所有主机
  • 我的码头文件:
FROM centos:7

RUN yum check-update; \
    yum install -y gcc libffi-devel python3 epel-release; \
    yum install -y python3-pip; \
    yum install -y wget; \
    yum clean all

RUN pip3 install --upgrade pip; \
    pip3 install "ansible"; \
    wget -q https://raw.githubusercontent.com/ansible-collections/azure/dev/requirements-azure.txt; \
    pip3 install -r requirements-azure.txt; \
    rm requirements-azure.txt; \
    ansible-galaxy collection install azure.azcollection \

WORKDIR /github
CMD ["/usr/sbin/init"]
  • 所有主机都是 Windows 操作系统主机
  • 在我的 Ansible 库结构下方
C:.
└───bla_product
    └───core
        ├───ansible
        │   ├───inventories
        │   │   ├───production
        │   │   ├───staging
        │   │   └───test
        │   │       ├───cloud
        │   │       └───onpremis
        │   │           └───domain.com
        │   │               │   lab_x.yml
        │   │               │
        │   │               └───group_vars
        │   │                       windows.yml
        │   │
        │   ├───playbooks
        │   └───roles
  • 我的库存文件 lab_x.yml 如下所示:
---
all:
  children:
    root:
      children:
        center:
          children:
            appservers:
              hosts:
                centeriis.domain.com:
                  ansible_host: 200.10.0.100
            qservers:
              hosts:
                centerq.domain.com:
                  ansible_host: 200.10.0.101
            dbservers:
              hosts:
                centerdb.domain.com:
                  ansible_host: 200.10.0.102
        serverfarms:
          hosts:
          children:
            gateways:
              hosts:
        south:
          children:
            brooklyn:
              hosts:
                  srv1.domain.com:
                    ansible_host: 200.10.0.103
              children:
                endpoints:
                  hosts:
                    client1.domain.com:
                      ansible_host: 200.10.0.105
                    client2.domain.com:
                      ansible_host: 200.10.0.106
        north:
          children:
            newyork:
              hosts:
                srv2.domain.com:
                  ansible_host: 200.10.0.104
              children:
                endpoints:
                  hosts:
                    client3.domain.com:
                      ansible_host: 200.10.0.107
  • 该windows.yml文件包含引用所有主机的连接详细信息,因为它们都是 Windows 操作系统主机:
---
ansible_connection: winrm
ansible_user: domain\user
ansible_password: password
  • 运行以下命令ansible all -i lab_r.yml -m win_ping结果:
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Nov 16 2020, 16:55:22) [GCC
 4.8.5 20150623 (Red Hat 4.8.5-44)]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by setting 
deprecation_warnings=False in ansible.cfg.
centeriis.domain.com | UNREACHABLE! => {
    "changed": false,
    "msg": "[Errno None] Unable to connect to port 22 on 200.10.0.100",
    "unreachable": true
}
  • 尝试这个ansible windows.yml -i lab_r.yml -m win_ping给出:
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Nov 16 2020, 16:55:22) [GCC
 4.8.5 20150623 (Red Hat 4.8.5-44)]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by setting 
deprecation_warnings=False in ansible.cfg.
[WARNING]: Could not match supplied host pattern, ignoring: windows.yml
[WARNING]: No hosts matched, nothing to do
  • 我在这个“故事”中缺少什么?
  • 文件或命令有问题吗?
  • Ansible 使用 22 端口而不是 WinRM 协议的原因是什么?
  • win_ping 命令可以在这个阶段工作还是我必须持有剧本和角色(任务)文件才能工作?
  • 如何使整个业务正常运行(使用 Inventories 和 group_vars 文件夹中的文件的命令)?
ansible devops
  • 1 1 个回答
  • 495 Views

1 个回答

  • Voted
  1. Best Answer
    Gerald Schneider
    2021-07-01T10:46:30+08:002021-07-01T10:46:30+08:00

    您的清单中的所有主机都不在名为“windows”的组中,因此您的 windows.yml 永远不会被使用,并且 Ansible 会回退到默认协议,即 ssh。

    如果您只有 Windows 服务器,最简单的解决方案是将连接信息放入 all.yml。

    • 1

相关问题

  • 重复的 Ansible 任务

  • 无法形成站点中的文件的链接,该链接可用于使用 ansible 在远程服务器中启用的目录站点?

  • 如何执行 ansible 的特定角色?

  • Ansible 和 rbash

Sidebar

Stats

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

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve