zoukankan      html  css  js  c++  java
  • ansible

    ansible
    安装ansible :yum install -y ansible
    查看版本:ansible --version
    配置ssh免密登录:ssh-keygen -t rsa -f /root/.ssh/id_rsa -P ""
    配置主机组:如果没有ansible目录创建即可,touch /etc/ansible/hosts
    配置ansible配置文件:touch /etc/ansible/ansible.cfg
    测试: ansible -m ping all
    
    Ansible常用模块使用
    shell模块:ansible k8s -m shell -a "chdir=/rubbish touch test.conf"
    command模块:ansible k8s -m command -a "chdir=/rubbish touch test.conf"
    replace模块(查找替换)
    ansible master -m replace -a "path=/etc/systemd/system/etcd.service regexp='master=' replace='$ECTD_CLUSTER' backup=yes"
    lineinfile模块:ansible master -m lineinfile -a "dest=/roota.sh line='listen'"
    copy模块:ansible test2 -m copy -a "src=/script/test2_hostname.py dest=/root/ backup=yes"
    script模块使用:ansible tes2 -m script -a "python test2_hostname.py"
    file模块:
    创建目录并授权方式一
    time ansible test2 -m file -a "path=/rubbish/test/ state=directory mode=0755"
    创建目录并授权方式二
    time ansible test2 -m file -a "dest=/rubbish/test/ state=directory mode=0755"
    删除文件
    time ansible k8s -m file -a 'path=/root/.kube/config state=absent'
    修改文件的所有者
    ansible test4 -m file -a 'path=/var/log/kubernetes/log.file state=touch mode="u=rw,g=r.o=r"'
    说明:state取值可以是directory、file、touch、link、hard、absent
    service模块:ansible k8s -m service -a 'name=nginx state=restarted'
    unarchive模块:
    time ansible test1 -m unarchive -a 'src=/server/software/k8s/flannel-v0.10.0-linux-amd64.tar.gz dest=/rubbish/'
    
    Ansible最佳实战(初始化roles进行部署nginx)
    初始化一个role   ansible-galaxy init /etc/ansible/roles/websrvs
    配置变量all文件,注意:名字只能写成all,写其他的就报错
    配置site.yaml作为执行入口文件,里面定义都对哪些roles操作
    配置handlers文件,就是触发器,比如满足条件后启动nginx
    配置tasks, 这是具体执行操作的yaml文件
    配置templates。  就是准备需要的模板文件,没有就不用准备
    执行部署   ansible-playbook site.yaml
  • 相关阅读:
    PAXOS: libevent_paxos
    R提高篇(五): 描述性统计分析
    R提高篇(四): 数据管理二
    R提高篇(三): 数据管理一
    锂电池知识
    R提高篇(二): 图形初阶
    R提高篇(一): 输入输出
    动力电池基本知识篇
    DW(六):polybase访问Azure Blob Storage
    DW(五):polybase集群安装
  • 原文地址:https://www.cnblogs.com/effortsing/p/10405206.html
Copyright © 2011-2022 走看看