一个简单的 Ansible playbook 针对大约 100 个主机的合理性能是多少?

use*_*814 11 ansible ansible-playbook

我们开始研究 Ansible 来替换旧的 cfengine2 安装。我有一个简单的剧本:

  • 复制 sudoers 文件
  • 复制模板化的 resolv.conf(输入 group_vars 和 host_vars 数据)
  • 检查几个服务正在运行
  • 检查本地用户的存在

该剧本需要超过 4 分钟的挂钟时间才能在 97 台机器上运行(全部通过快速 1gig 或 10gig 网络连接,LAN 延迟低于 1 毫秒),并且在我使用 2 核 4G 内存 VM 时消耗了超过 50% 的 CPU运行它。

在单台机器上运行大约需要 11 秒,消耗了大约 4 秒的用户+系统 CPU 时间,对于所涉及的工作量来说,TBH 似乎仍然有点过分。

明显的位:

  • 我在 playbook-dir local ansible.cfg 中明确启用了流水线
  • 我启用了对 jsonfile 的事实缓存,相同的本地 ansible.cfg
  • 我将叉设置为 50,相同(我尝试过其他值)
  • 我确信 Ansible 使用的是 SSH 而不是 Paramiko,它使用的是持久控制套接字——我可以看到 SSH 进程正在启动并在运行期间持续存在。

这种性能水平是正常的还是我的设置有问题?如果是这样,我该如何确定什么?

编辑:截至 2017 年 8 月,我们仍然看到这个问题。Ansible 版本是 2.2.1,现在剧本的大小已经增加。最新数字:

  • 98台主机
  • ansible -m ping all 实际需要 4.6 秒,用户需要 3.2 秒,系统时间需要 2.5 秒
  • 完整的 playbook 运行需要 4 分钟,同时使用 100% 的用户和 ~35% 的系统 CPU(在 2 核 VM 部署服务器上,100% 是一个完整的 CPU)
  • 目标操作系统主要是 CentOS 7,一些是 CentOS 6
  • 分析不会显示任何特定的任务热点 AFAICT

尽管剧本现在更大了,但我仍然认为没有任何东西可以证明剧本服务器上的 CPU 负载水平是合理的 - 也许是挂钟时间,但部署服务器在大部分运行中应该基本上处于空闲状态,据我所知,它主要是文件副本和一些模板扩展。

请注意,我们正在大量使用主机/组变量

有几个人询问了分析,分析运行的尾部:

Tuesday 01 August 2017  16:02:24 +0100 (0:00:00.539)       0:06:22.991 ******** 
=============================================================================== 
yumrepo : centos repos -------------------------------------------------- 9.77s
sshd : copy CentOS 6 sshd config ---------------------------------------- 7.41s
sshd : copy CentOS 7 sshd config ---------------------------------------- 6.94s
core : ensure core packages are present --------------------------------- 6.28s
core : remove packages on VM guests ------------------------------------- 5.39s
resolv : stop NetworkManager changing resolv.conf ----------------------- 5.25s
yumrepo : epel6 gpg key ------------------------------------------------- 3.94s
yumrepo : epel7 gpg key ------------------------------------------------- 3.71s
yumrepo : nsg gpg key --------------------------------------------------- 3.57s
resolv : build resolv.conf ---------------------------------------------- 3.30s
yumrepo : nsg repo ------------------------------------------------------ 2.66s
resolv : check NetworkManager running ----------------------------------- 2.63s
yumrepo : psp repo ------------------------------------------------------ 2.62s
yumrepo : ucs repo ------------------------------------------------------ 2.44s
yumrepo : epel repo ----------------------------------------------------- 2.27s
resolv : check for nmcli ------------------------------------------------ 2.08s
core : remove various unwanted files ------------------------------------ 1.42s
telegraf : write telegraf.conf file ------------------------------------- 1.13s
core : copy sudoers in place -------------------------------------------- 0.94s
core : ensure sshd is running ------------------------------------------- 0.90s
Run Code Online (Sandbox Code Playgroud)

xdd*_*dsg 1

在您的ansible.cfg设置中包含以下内容:

[defaults]

# profile each task
callback_whitelist = profile_tasks

# [don't validate host keys](http://docs.ansible.com/ansible/intro_configuration.html#host-key-checking)
host_key_checking = False

[ssh_connection]
pipelining = True
Run Code Online (Sandbox Code Playgroud)

另外,在您的剧本中,将策略设置为“免费”

- hosts: all
  strategy: free
  tasks: [...]
Run Code Online (Sandbox Code Playgroud)

最后,禁用游戏中的事实收集:gather_facts: false

如果在分析之后,您看到很多这样的内容:

TASK [pip foo]
ok: [10.192.197.252] => (item=ansible)
ok: [10.192.197.252] => (item=boto)
ok: [10.192.197.252] => (item=boto3)
ok: [10.192.197.252] => (item=passlib)
ok: [10.192.197.252] => (item=cryptography)
Run Code Online (Sandbox Code Playgroud)

将这些操作压缩在ansible.cfg[默认值]下:

例如squash_actions = yum,pip,bar