ansible操作随记(一)

0、其他

shell 复制代码
#shell模块 执行shell指令
ansible all -m shell -e "timedatectl show"
ansible web -m shell -a "date"

 ansible web -m shell -a "echo '*       soft     nofile     1048576' >> /etc/security/limits.conf"  -b --become-method su --become-user root 
  ansible web -m shell -a "echo '*       hard     nofile     1048576' >> /etc/security/limits.conf"  -b --become-method su --become-user root 
 ansible web -m shell -a "tail /etc/security/limits.conf"
 ansible web -m shell -a "ulimit -a"
  ansible hadoop -m shell -a "ls /etc/ambari-agent/conf/ambari-agent.ini"
 ansible hadoop -m shell -a "ambari-agent status"
  ansible web -m shell -a "yum install -y java-11-openjdk java-11-openjdk-devel"  -b --become-method su --become-user root 
   ansible web -m shell -a "java -version"
   ansible web -m shell -a "jps -ml" 
 
 #copy模块,远程拷贝
 ansible gxtest-117 -m copy -a "src=/home/test/packages/bigtop-3.2.0.zip dest=/data/" -b --become-method su --become-user root 
 ansible gxtest-117 -m copy -a "src=/home/test/packages/ambari-2.8.0.zip dest=/data/" -b --become-method su --become-user root 
 ansible gxtest-117 -m copy -a "src=/home/test/packages/mysql-connector-java-8.0.28.jar dest=/data/" -b --become-method su --become-user root 
 ansible gxtest-117 -m copy -a "src=/home/test/packages/mysql-8.0.36-1.el8.x86_64.rpm-bundle.tar dest=/data/" -b --become-method su --become-user root 
ansible test -m copy -a "src=/data/xxx/conf/application.xml dest=/data/xxx/conf/" 
ansible sdtp -m copy -a "src=/data/sxxxhdfs dest=/data/" 

#script模块,执行脚本内容。
ansible test -m script -a "start_xxx.sh" 
 
 

1、ansible每天2点执行脚本clear.sh

yaml 复制代码
addCrontab.yml 内容:
---
- name: Add cron job for clearing bad backups
  hosts: web
  become: yes
  become_user: test
  tasks:
    - name: Add cron job
      ansible.builtin.cron:
        name: "clearBadBak"
        minute: "0"
        hour: "2"
        job: "/bin/bash /home/shellDir/clea.sh"
 
 执行:ansible-playbook addCrontab.yml 

删除crontab操作:
---
- name: Remove cron job
  hosts: web
  become: yes
  become_user: test
  tasks:
    - name: Ensure cron job is absent
      ansible.builtin.cron:
        name: "clearBadBak"
        state: absent
相关推荐
我爱学习好爱好爱21 小时前
Ansible变量介绍 vars变量 inventory针对主机设置变量
linux·自动化·ansible
我爱学习好爱好爱21 小时前
inventory针对主机组设置变量 host_vars group_vars playbook执行时传入值 Ansible-register
运维·自动化·ansible
我爱学习好爱好爱1 天前
Ansible 自动化部署Elasticsearch + Logstash + Kibana实战(基于RockyLinux 9.6)
elasticsearch·自动化·ansible
牛奶咖啡132 天前
DevOps自动化运维实践_自动化运维工具Ansible
运维·自动化·ansible·devops·ansible的安装·ansible的架构与运行原理·ansible的主机和组配置
我爱学习好爱好爱2 天前
Ansible Playbook介绍 playbook的编写要求 playbook多任务案例
linux·运维·ansible
我爱学习好爱好爱2 天前
Ansible 常用模块详解:firewalld、setup实战
linux·运维·ansible
SPC的存折2 天前
4、Ansible之Playbook变量应用
linux·前端·chrome·ansible
淼淼爱喝水2 天前
openEuler 下 Ansible 基础命令详解与实操演示1
linux·服务器·ansible
我爱学习好爱好爱2 天前
Ansible 自动化部署Prometheus + Alertmanager + Grafana实战(Rockylinux9.6)
自动化·ansible·prometheus
我爱学习好爱好爱3 天前
Ansible 常用模块详解:cron、archive、unarchive实战
linux·服务器·ansible