首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用win_ping来存放库存和group_vars文件?

如何用win_ping来存放库存和group_vars文件?
EN

Server Fault用户
提问于 2021-06-29 20:22:25
回答 1查看 861关注 0票数 1
  • 我正在尝试编写一个正确的命令行,它将对库存文件中详细列出的所有主机进行ping操作。
  • 我的伪造文件:
代码语言:javascript
复制
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主机
  • 在我的虚拟图书馆结构下面
代码语言:javascript
复制
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如下所示:
代码语言:javascript
复制
---
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主机:
代码语言:javascript
复制
---
ansible_connection: winrm
ansible_user: domain\user
ansible_password: password
  • 运行以下命令ansible all -i lab_r.yml -m win_ping结果:
代码语言:javascript
复制
[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会给出如下结果:
代码语言:javascript
复制
[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命令可以在这个阶段工作吗?或者我必须持有一个剧本和角色(任务)文件才能工作?
  • 如何使整个业务正常工作(使用库存和group_vars文件夹中的文件的命令)?
EN

回答 1

Server Fault用户

回答已采纳

发布于 2021-06-30 18:46:30

库存中没有一个主机位于一个名为"windows“的组中,因此您的windows.yml从未被使用过,Ansible回到了默认协议ssh中。

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

票数 1
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/1068201

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档