ansible&ansible-playbook

ansible常用命令

#批量远程连接服务器执行shell操作
ansible test_group -m shell -a "df -h /data "

#批量下发本地文件到远程服务器/tmp目录
ansible 127.0.0.1,127.0.0.2 -m copy -a "src=./aa  dest=/tmp"

#批量检测主机组是否可联通
ansible  test_group  -m fping

#创建目录
ansible test_group -m file -a 'path=/tmp/d1 state=directory owner=root group=root mode=755'  

#批量yum安装rsync
ansible test_group  -m yum  -a 'name=rsync  state=lastest'

#远程添加crond任务
ansible test_group -m cron -a "name='ntpdate' minute=5 hour=1 job='ntpdate ntp.aliyun.com'"

#停止crond任务
ansible test_group  -m cron -a "name='ntpdate' minute=5 hour=1 job='ntpdate ntp.aliyun.com' disabled=yes"

#删除crond任务
ansible test_group -m cron -a "name='ntpdate' state=absent backup=yes"

#参数补充
-i 指定参数文件

#cat ./ansible.ini
[all:vars]
ansible_ssh_port=22
ansible_ssh_user=ansible
ansible_ssh_private_key_file=/home/ansible/.ssh/id_rsa
ansible_become=true
ansible_become_user=root
host_key_checking=False

[server_group]
10.0.0.1
10.0.0.2

# ansible -i ./ansible.ini test_group -m shell -a "md5sum /tmp/aa "

ansible-playbook剧本示例

#1、编辑剧本入口yml
# cat sys_core_parm.yml
---
- name: sys_core_parm
  hosts:
#    - redis_group
    - 10.102.21.30

  become: true
  gather_facts: no
  vars:
    is_redisms_pyh: false #false/true
  roles:
    - sys_core_parm

#2、编辑剧本task主yml
# cat roles/sys_core_parm/tasks/main.yml 
#- sysctl:
#    name: net.core.somaxconn
#    value: 65535
#    state: present

#- sysctl:
#    name: net.core.netdev_max_backlog
#    value: 65535
#    state: present

#- sysctl:
#    name: net.ipv4.tcp_max_syn_backlog
#    value: 65535
#    state: present

- sysctl:
    name:  net.nf_conntrack_max
    value: 524288
    state: present

- sysctl:
    name: vm.overcommit_ratio
    value: 80  #default 50
    state: present

#- sysctl:
#    name: net.ipv4.conf.default.rp_filter
#    value: 2
#    state: present
#  when:
#     - is_redisms_pyh == true

#- sysctl:
#    name: net.ipv4.conf.all.rp_filter 
#    value: 2
#    state: present
#  when:
#     - is_redisms_pyh == true

#- stat: path=/sys/kernel/mm/transparent_hugepage/enabled
#  register: transparent_hugepage_stat

#3、执行剧本
ansible-playbook  sys_core_parm.yml

#4、参数补充
#外传入指定参数变量值,多个变量之间空格分割
--extra-vars "slowlog_log_slower_than='50000'"
 
# ansible-playbook redis_slowlog.yml  --extra-vars "slowlog_log_slower_than='50000'"
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇
Secured By miniOrange