大网数据广告活动
服务器运维问答

How to win_ping to hosts with inventory and group_vars files?

· 52CE 我爱测

I'm trying to write a correct command line that will ping to all hosts that are detailed in my inventory file my dockerfile: FROM centos:7 RUN yum check-update; \ yum install -y gcc libffi-devel python3 epel-release; \ yum instal…

问题原文

原帖链接 · Hiddai · CC BY-SA 4.0

  • I'm trying to write a correct command line that will ping to all hosts that are detailed in my inventory file
  • my dockerfile:
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"]
  • All hosts are Windows OS hosts
  • Below my Ansible library structure
C:.
└───bla_product
    └───core
        ├───ansible
        │   ├───inventories
        │   │   ├───production
        │   │   ├───staging
        │   │   └───test
        │   │       ├───cloud
        │   │       └───onpremis
        │   │           └───domain.com
        │   │               │   lab_x.yml
        │   │               │
        │   │               └───group_vars
        │   │                       windows.yml
        │   │
        │   ├───playbooks
        │   └───roles
  • my inventory file lab_x.yml looks like this:
---
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
  • The windows.yml file include connection details that refers to all hosts, since they are all Windows OS hosts:
---
ansible_connection: winrm
ansible_user: domain\user
ansible_password: password
  • Run the following command ansible all -i lab_r.yml -m win_ping results:
[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
}
  • trying this one ansible windows.yml -i lab_r.yml -m win_ping gives:
[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
  • What am I missing in this "story"?
  • Is the problem with files OR commands?
  • What is the reason that Ansible uses port 22 instead using WinRM protocol?
  • Can win_ping command can works in this phase OR must I hold a playbook and role (task) files in order it to be worked?
  • How do I make this whole business work (a command that uses the files within Inventories and group_vars folder)?

已采纳解答

原帖链接 · Gerald Schneider · CC BY-SA 4.0

None of the hosts in your inventory is in a group called "windows", so your windows.yml is never used and Ansible falls back to the default protocol, which is ssh.

If you only have Windows servers the easiest solution would be to put the connection information into all.yml.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-06-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。