ansible-playbook系列之apt更新软件

apt_upgrade.yml

root下

---
- name: init_application
  hosts: execgroup
  remote_user: root
  gather_facts: true

  tasks:
    - name: Update apt cache
      apt:
        update_cache: yes
      tags: update

    - name: Install and upgrade software
      apt:
        name: 
          - chrony
          - forta
          - pkg-config
        state: latest
        force_apt_get: yes

非root下

---
- name: init_application
  hosts: execgroup
  remote_user: gcore
  gather_facts: true
  become: true
  become_user: root
  vars:
    ansible_become_password: "gcorepassword" # sudo password for gcore user

  tasks:
    - name: Update apt cache
      apt:
        update_cache: yes
      tags: update

    - name: Install and upgrade software
      apt:
        name: 
          - chrony
          - forta
          - pkg-config
        state: latest
        force_apt_get: yes

state

在 Ansible 的 apt 模块中,state 参数用于控制包的状态,常见的几种类型包括:
present:确保包已安装。如果包没有安装,它会被安装。如果已经安装,则不会有任何操作。
absent:确保包已卸载。如果包存在,则会将其卸载。
latest:确保包为最新版本。如果系统有较新的版本,则会自动升级到最新版本。
build-dep:安装指定包的编译依赖项。
fixed:确保包锁定为当前版本,不会升级。
forcibly-removed:使用 dpkg –purge –force-remove-reinstreq 强制删除。
purged:不仅卸载包,还会删除包的配置文件。
这些是 Ansible 中 apt 模块的 state 参数的主要选项,最常用的还是 present、latest 和 absent。

暂无评论

发送评论 编辑评论


|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇