前言
记录一下常用的ansible task中常用命令
注意记录时间和版本号
--- 记录于 2021年8月
环境
ubuntu 20.04
ansible 2.9.20
官方文档
https://docs.ansible.com/ansible/latest/user_guide/index.html
1、脚本相关
- 执行shell
- name: Add route
command: /sbin/ip route add 10.250.129.0/24 dev eth0
2、文件文本相关
- 复制
- name: Copy sources.list
copy:
src: sources.list.stretch
dest: /etc/apt/sources.list
- 修改文字
- name: Update monit service
lineinfile:
path: /etc/init.d/monit
regexp: '^CONFIG='
line: 'CONFIG=/root/monitrc'
- 删除文件
- name: Remove tunnel service
file:
path: /etc/systemd/system/node-exporter-tunnel.service
state: absent
3、安装卸载相关
- 安装
- name: Install tcpdump
apt:
name: tcpdump
update_cache: yes
- 卸载
- name: Uninstall ntpd
apt:
name: ntp
state: absent
4、服务相关
- 设置开机自启动
- name: Enable systemd-timesyncd service
systemd:
name: systemd-timesyncd
state: restarted
enabled: yes
daemon_reload: yes
- 关闭开机自启动
- name: Disable autossh-tunnel service
systemd:
name: autossh-tunnel
state: stopped
enabled: no
daemon_reload: yes
ignore_errors: yes
- 重启服务
- name: Restart journald service
systemd:
name: systemd-journald
state: restarted
5、 其他
- 设置时区
- name: Set timezone to Asia/Shanghai
timezone:
name: Asia/Shanghai
- 添加定时任务
- name: Add cronjob
cron:
name: "cell_mgmt.sh"
user: root
job: "/root/cell_mgmt.sh | sponge /root/cell_mgmt.prom"
cron_file: /etc/crontab
其他
如有问题 欢迎补充
如有疑问 欢迎提出
如有作用 欢迎点赞