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
相关推荐
学Linux的语莫2 小时前
Ansible Playbook剧本用法
linux·服务器·云计算·ansible
qq_383139847 小时前
ansible playbook安装nacos
ansible
Aimyon_364 天前
⾃动化运维利器 Ansible-Jinja2
运维·ansible
柒月VII5 天前
【Ansible常用命令+模块+Playbook+Roles】
linux·服务器·ansible
Linux运维技术栈5 天前
生产环境centos8 & Red Hat8部署ansible and 一键部署mysql两主两从ansible脚本预告
运维·数据库·mysql·自动化·ansible
Aimyon_365 天前
⾃动化运维利器 Ansible-最佳实战
linux·运维·ansible
饭桶也得吃饭5 天前
运维工具Ansible部署、配置
运维·服务器·ansible
陪小七许个愿5 天前
Ansible一键部署Kubernetes集群
容器·kubernetes·ansible
Aimyon_366 天前
⾃动化运维利器 Ansible-变量
运维·ansible