章工运维 章工运维
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)

章工运维

业精于勤,荒于嬉
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)
  • ansible系列文章

    • ansible入门
    • anisble批量安装node_exporter
    • ansible-playbook中的变量
    • Ansible性能优化——提升ansible执行效率
    • ansible之roles简单使用
    • ansible中template简单使用
    • playbook详解
    • ansible-playbook编排使用tips
    • ansible优秀案例
      • 如何优雅向chatgpt提问ansible相关问题
    • Kubernetes笔记

    • elk

    • jenkins

    • GitLabCI_CD

    • 专题
    • ansible系列文章
    章工运维
    2023-01-29
    目录

    ansible优秀案例

    # 优化的取消交换分区

    - name: Remove swapfile from /etc/fstab
      mount:
        name: "{{ item }"
        fstype: swap
        state: absent
      with_items:
        - swap
        - none
    - name: check swap
      command: /sbin/swapon -s
      register: swapon
      changed_when: no
    - name: Disable swap
      command: /sbin/swapoff -a
      when:
        - swapon.stdout
      ignore_errors: yes
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    - name: shutdown  get the status of swap
      shell: grep swap /etc/fstab l grep -c "#
      register: swap
      ignore errors: yes
      tags: swap
    - name: shutdown  swapoff -a
      shell: swapoff -a
      when: swap.stdout == "0"
      ignore errors: yes
      tags: swap
    - name: shutdown | 注释/etc/fstab/swap 那一行
      replace: dest=/etc/fstab regexp='(.*) swap(\s+) swap' replace='f  swap\2swap'
      when: swap.stdout == "0"
      ignore errors: yes
      tags: swap
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    微信 支付宝
    上次更新: 2024/10/22, 18:10:01

    ← ansible-playbook编排使用tips 如何优雅向chatgpt提问ansible相关问题→

    最近更新
    01
    不花一分钱从0到1建站教程
    04-22
    02
    批量拿取多台服务器的日志文件
    04-21
    03
    高德MCP智能体搞定旅游计划
    04-19
    更多文章>
    Theme by Vdoing | Copyright © 2019-2025 | 点击查看十年之约 | 鄂ICP备2024072800号
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式