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

Ansible "warm up" deployment

· 52CE 我爱测

I have the playbook below (simplified). It works great, but I'd like to be able to do a warmup where I only deploy to a single host (like serial: 1) and then pause so I can check logs to verify everything is fine before releasing…

问题原文

原帖链接 · Brando__ · CC BY-SA 3.0

I have the playbook below (simplified).

It works great, but I'd like to be able to do a warmup where I only deploy to a single host (like serial: 1) and then pause so I can check logs to verify everything is fine before releasing to something as large as 33% of all my services.

Is there an easy way Ansible lets you do this?

I have a really hacky solution in place right now involving essentially copy and pasting my code with serial: 1, a fail statement, a pile of when checks and command line arguments. There has to be a better way than ruining an otherwise clean and readable playbook. I'm just not sure what it might be.

- name: 33% at a time max-analytics deploy
  hosts: role_max_logger
  serial: 33%
  tasks:
    - name: take out of lb analytics
      shell: haproxy stuff
    - pause:
        seconds: 5
    - name: gracefulReloading max-analytics
      shell: reload stuff
    - name: add back to lb analytics
      shell: haproxy stuff

已采纳解答

原帖链接 · Konstantin Suvorov · CC BY-SA 3.0

As of Ansible 2.2 you can set dynamic batch size.

---
- hosts: mygroup
  serial:
   - 1
   - 33%
  tasks:
    - shell: date
    - pause:
        prompt: check if everything ok
      when: ansible_play_hosts.index(inventory_hostname) == 0

This will take only one host in the first batch, execute date command on that host and pause if the current host is the first in play hosts. So it'll pause only once and then 33% batches will go without pausing.

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

资料来源与适用范围

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

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

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