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

...

相关推荐
MichealChen01050825 分钟前
Influxdb-cluster使用docker部署
运维·docker·容器
wqfhenanxc37 分钟前
AirFlow安装和使用
运维
守城小轩39 分钟前
Chromium 145 编译指南 Windows篇:获取源代码(五)
自动化·chrome devtools·浏览器自动化·指纹浏览器·浏览器开发
北京耐用通信1 小时前
工业自动化领域耐中达讯自动化CC-Link IE转EtherCAT技术解决方案
人工智能·物联网·网络协议·自动化·信息与通信
阿凤211 小时前
nginx部署如何配置ssl证书
运维·nginx·ssl
安审若无1 小时前
Windows系统常用的运维终端安全基线设置方法
运维·安全
橙露1 小时前
Linux 驱动入门:字符设备驱动框架与编写流程
linux·运维·服务器
仙俊红2 小时前
关于ssh免密登录
运维·ssh
斯普信云原生组2 小时前
Docker 开源软件应急处理方案及操作手册——安全漏洞与权限问题
运维·docker·容器
星马梦缘2 小时前
运动控制系统(三)-转速闭环直流调速系统
自动化·电机·自动控制·闭环系统