RedHat运维-Ansible自动化运维基础27-管理启动进程和计划任务

  1. ansible.posix.at:写一个playbook,让所有的受控主机在20分钟之后,执行命令ls -d / >/dev/null,确保这个任务是独一无二的;

  2. ansible.posix.at:写一个playbook,确保任务ls -d / >/dev/null不存在;

  3. ansible.posix.cron:写一个playbook,对于用户centos,每天的2点和5点都会运行任务ls -alh > /dev/null;

  4. ansible.posix.cron:写一个playbook,对于用户centos,每周五16点每隔两分钟,都会运行任务ls -alh > /dev/null;

  5. ansible.builtin.service:启动并开机自启httpd服务;

  6. ansible.builtin.systemd:启动并开机自启httpd服务;

  7. ansible.builtin.systemd:重新加载所有对于httpd配置的改动,然后重启httpd服务;

  8. ansible.builtin.command:写一个playbook,将默认target设置为multi-user.target;

  9. ansible.builtin.reboot:重启受控主机;

  10. /* A20240605.yaml */


  • name: Play1

hosts: all

tasks:

  • name: Task1

ansible.posix.at:

command: ls -d / >/dev/null

count: 20

units: minutes

unique: yes

...

  1. /* B20240605.yaml */

  • name: Play1

hosts: all

tasks:

  • name: Task1

ansible.posix.at:

command: ls -d / >/dev/null

state: absent

...

  1. /* C20240605.yaml */

  • name: Play1

hosts: all

tasks:

  • name: Task1

ansible.builtin.cron:

user: centos

name: job1

job: "ls -alh > /dev/null"

hour: "2,5"

...

  1. /* D20240605.yaml */

  • name: Play1

hosts: all

tasks:

  • name: Task1

ansible.builtin.cron:

user: centos

name: job2

job: "ls -alh > /dev/null"

weekday: "5"

hour: "16"

minute: "*/2"

...

  1. /* E20240605.yaml */

  • name: Play1

hosts: all

tasks:

  • name: Task1

ansible.builtin.service:

name: httpd

state: started

enabled: true

...

  1. /* F20240605.yaml */

  • name: Play1

hosts: all

tasks:

  • name: Task1

ansible.builtin.systemd:

name: httpd

state: started

enabled: true

...

  1. /* G20240605.yaml */

  • name: Play1

hosts: all

tasks:

  • name: Task1

ansible.builtin.systemd:

name: httpd

state: reloaded

daemon_reload: yes

...

  1. /* H20240605.yaml */

  • name: Play1

hosts: all

vars:

  • target: multi-user.target

tasks:

  • name: Task1

ansible.builtin.command:

cmd: systemctl get-default

changed_when: false

register: Task1result

  • name: Task2

ansible.builtin.command:

cmd: systemctl set-default {{ target }}

when: target not in Task1result.stdout

...

  1. /* I20240605.yaml */

  • name: Play1

hosts: centos7.example.com,centos8.example.com

tasks:

  • name: Task1

ansible.builtin.reboot:

reboot_timeout: 180

...

相关推荐
碳基沙盒1 天前
OpenClaw 多 Agent 配置实战指南
运维
蝎子莱莱爱打怪4 天前
Centos7中一键安装K8s集群以及Rancher安装记录
运维·后端·kubernetes
DianSan_ERP5 天前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet
呉師傅5 天前
火狐浏览器报错配置文件缺失如何解决#操作技巧#
运维·网络·windows·电脑
不是二师兄的八戒5 天前
Linux服务器挂载OSS存储的完整实践指南
linux·运维·服务器
zhangfeng11335 天前
趋动云 如何ssh登录 服务区 项目server
运维·人工智能·ssh
ZeroNews内网穿透5 天前
谷歌封杀OpenClaw背后:本地部署或是出路
运维·服务器·数据库·安全
失重外太空啦5 天前
nginx
运维·nginx
Gofarlic_oms15 天前
避免Kisssoft高级分析模块过度采购的科学评估方法
大数据·linux·运维·人工智能·matlab
田井中律.5 天前
服务器部署问题汇总(ubuntu24.04.3)
运维·服务器