[Ansible] 升级 CentOS 到指定版本

今天接到一个需求,需要把一些 7.4 版本的 CentOS 升到 7.5 而不是 7.6。
查了一下手动升级的方案,然后写成 ansible playbook。做个记录。

- hosts: all
  become: yes
  serial: 
    - 1
    - 33%
  vars:
    upgrade_to: "7.5.1804"
    repo_server: "http://vault.centos.org"
  tasks:
    - name: Checking OS release
      assert:
        that:
          - ansible_distribution == 'CentOS'
          - ansible_distribution_version is version(upgrade_to, operator='lt', strict=True)
    - name: "Add repo {{ repo_server }}"
      yum_repository:
        name: "{{ item }}-{{ upgrade_to }}"
        file: "upgrade_to_{{ upgrade_to }}"
        description: "CentOS repo {{ item }} {{ upgrade_to }}"
        baseurl: "http://vault.centos.org/{{ upgrade_to }}/{{ item }}/$basearch"
        gpgcheck: no
        enabled: yes
      with_items:
        - os
        - updates
        - extras
    - name: "Upgrade system to {{ upgrade_to }}"
      yum:
        name: '*'
        state: latest
        releasever: "{{ upgrade_to }}"
        enablerepo: "*-{{ upgrade_to }}"
        disablerepo: "*"
上一篇:阿里云linux服务器和windows服务器有何不同


下一篇:如何选择阿里云服务器ECS的操作系统(新手参考指南)