ansible 示例

ansible-doc  文档帮助命令  
ansible-doc -l  查看有哪些模块
ansible-doc MOD 查看每个模块的文档

推荐一个 很好的修改文件内容的模块  lineinfile


1、通过ansible安装salt
#/etc/ansible/salt.yml

 - name: install salt-minion
   hosts: init_salt
   user: root
   #sudo: yes
   #sudo_user: root
   roles:
     - salt-minion
  
#/etc/ansible/roles 
 salt-minion/
├── handlers
│   └── main.yml
  - name: restart salt-minion
     service: name=salt-minion state=restarted
        
├── tasks
│   └── main.yml
  - name: salt.repo sync
   sudo: yes
   copy: src=/etc/yum.repos.d/saltstack.repo dest=/etc/yum.repos.d/saltstack.repo
 - name: python update
   sudo: yes
   yum: name=python state=latest
 - name: yum install salt-minion
   sudo: yes
   yum: name=salt-minion state=installed
 - name: copy salt-minion configuration
   sudo: yes
   template: src=minion dest=/etc/salt/minion
   notify:
      - restart salt-minion       
└── templates
    └── minion      

##################################################################

2 批量创建日志目录
#/etc/ansible/mk_log_dir.yml
 - name: init pay-serv env
   hosts: new-pay-serv
   user: root
   #sudo: yes
   #sudo_user: root
   roles:
     - pay_env_init
#/etc/ansible/roles 
pay_env_init/
├── handlers
│   └── main.yml
├── tasks
│   └── main.yml
 - name: add  users
   user: name={{item.name}} state=present
   with_items:
   - {name: 'webuser'}
   - {name: 'search'}
   - {name: 'tuanbuydev'}
 - name: create dir
   file: state=directory recurse=yes path=/var/log/java/{{item.dir}} owner={{item.owner}}
   with_items:
    - {dir: 'cashier-bill', owner: 'webuser'}
    - {dir: 'coupon-manage', owner: 'webuser'}
    - {dir: 'coupon-server', owner: 'webuser'}
    - {dir: 'pay-server', owner: 'webuser'}
    - {dir: 'pay-serverfkaRefund', owner: 'webuser'}
    - {dir: 'pay-serverfkaTransferLog', owner: 'webuser'}
    - {dir: 'search', owner: 'search'}
    - {dir: 'supervisor', owner: 'root'}
    - {dir: 'tuanbuy', owner: 'webuser'}
    - {dir: 'tuanbuy-pub-api', owner: 'webuser'}
    - {dir: 'tuanbuy-pub-manage', owner: 'webuser'}
    - {dir: 'tuan-pay-api', owner: 'webuser'}
    - {dir: 'tuan-pay-manage', owner: 'webuser'}
    - {dir: 'webuser', owner: 'webuser'}
    - {dir: 'zhebuy-api', owner: 'webuser'}
    - {dir: 'zhebuy-manage', owner: 'webuser'}
    - {dir: 'zhebuy-opt-server', owner: 'webuser'}
    - {dir: 'zhebuy-task', owner: 'webuser'}
    - {dir: 'zhepay-pos', owner: 'webuser'}
    - {dir: 'zhepay-payway', owner: 'webuser'}
 - name: rsync hosts
   template: src=hosts dest=/etc/hosts
└── templates
    └── hosts
######################################################
3、node 环境初始化、node项目安装
#/etc/ansible/node_env_init.yml
 - name: node_env_init
   hosts: pina_pre
   user: root       # ssh as with root
   sudo: yes        # sudo on 
   sudo_user: webuser #sudo user
   roles:
     - node_env_init
#/etc/ansible/roles/node_env_init
node_env_init/
├── handlers
│   └── main.yml
├── tasks
│   └── main.yml
 - name: install depention rpms
   yum: name={{item.name}} state=installed
   with_items:
   - {name: 'cairo'}
   - {name: 'cairo-devel'}
   - {name: 'cairomm-devel'}
   - {name: 'libjpeg-turbo-devel'}
   - {name: 'pango'}
   - {name: 'pango-devel'}
   - {name: 'pangomm'}
   - {name: 'pangomm-devel'}
   - {name: 'giflib-devel'}
 - name: useradd
   user: name=webuser state=present generate_ssh_key=yes
 - name: sync git keys
   copy: src={{item}} dest=/home/webuser/.ssh/ mode=0600 owner=webuser group=webuser
   with_fileglob:
   - /root/keys/*
 - name: maker dir
   file: path={{item.dir}} owner=webuser group=webuser state=directory recurse=yes
   with_items:
   - {dir: '/var/www/ued'}
   - {dir: '/var/www/node'}
   - {dir: '/var/www/sites/'}
   - {dir: '/home/webuser'}
 - name: wget node-v0.12.7
   get_url: dest=/root/ force=yes url=https://nodejs.org/dist/v0.12.7/node-v0.12.7.tar.gz 
 - name: install node
   shell: tar xf /root/node-v0.12.7.tar.gz -C /root/ && cd /root/node-v0.12.7 && ./configure && make && make install
 - name: npm install pm2
   npm: name=pm2@0.14.3  global=yes  registry=http://npm.tuan800-inc.com
 - name: git clone
   sudo: yes
   git : repo={{item.giturl}} dest={{item.dir}} update=yes accept_hostkey=yes   #key_file=/home/webuser/.ssh/update 
   with_items:
#   - {giturl: 'git@tuan800:trade_ued/serv_pin.git' ,dir: '/var/www/sites/serv_pin/'}
   - {giturl: 'git@tuan800:trade_ued/serv_p8.git' ,dir: '/var/www/sites/serv_p8/serv_p8'}
   #- {giturl: 'git@git.tuan800-inc.com:trade_ued/serv_pin.git' ,dir: '/var/www/node/'}
   register: test
 - debug: var=test
 - name: npm i based on package.json
   sudo: yes
   npm: path={{item.dir}}/package.json global=no registry=http://npm.tuan800-inc.com
   with_items:
   - {dir: '/var/www/sites/serv_p8/serv_p8'}
#   - {dir: '/var/www/sites/serv_pin/serv_pin'}

└── templates

###########################################################################

Pingbacks已打开。

引用地址

评论
  1. Payday Express Payday Express 发布于 2021年4月18日 01:49 #

    <a href="http://clevlending.com/">top debt consolidation companies</a> <a href="http://priolending.com/">loans in maryland</a>

  2. KimGal KimGal 发布于 2021年4月18日 02:42 #

    <a href="http://tmviagra.com/">sildenafil medication</a>

  3. JaneGal JaneGal 发布于 2021年4月18日 03:00 #

    <a href="http://viagrazpt.com/">75 mg sildenafil</a>

  4. EvaGal EvaGal 发布于 2021年4月18日 04:56 #

    <a href="http://viagrahere.com/">sildenafil buy online usa</a>

  5. Quick Loan Quick Loan 发布于 2021年4月18日 07:20 #

    <a href="https://paydayloansos.com/">loans online instant approval</a>

  6. NickGal NickGal 发布于 2021年4月18日 07:23 #

    [url=http://cialispwr.com/]buy cialis tablets[/url] [url=http://cialiseff.com/]cialis 5mg daily coupon[/url] [url=http://hereviagra.com/]sildenafil generic drug cost[/url] [url=http://cialissx.com/]cialis 20mg uk online[/url] [url=http://npropills.com/]canadian pharmacy generic levitra[/url] [url=http://cialisdx.com/]tadalafil 100[/url] [url=http://cialisprem.com/]cheap cialis for daily use[/url]

  7. NickGal NickGal 发布于 2021年4月18日 09:26 #

    <a href="http://midviagra.com/">suhagra</a> <a href="http://cialisvm.com/">cialis cream</a> <a href="http://ethpharm.com/">purchase sildenafil 100 mg</a> <a href="http://viagraoctab.com/">price of viagra</a> <a href="http://viagradist.com/">over the counter generic sildenafil</a>

  8. LisaGal LisaGal 发布于 2021年4月18日 09:40 #

    [url=https://srxstore.com/]order levitra online uk[/url]

  9. SamGal SamGal 发布于 2021年4月18日 10:01 #

    <a href="http://viagrazpt.com/">how to get viagra in canada</a> <a href="http://555pharmacy.com/">pharmacy prices</a> <a href="http://viagractab.com/">can you buy sildenafil online</a>

  10. JackGal JackGal 发布于 2021年4月18日 10:04 #

    <a href="http://viagractab.com/">sildenafil women</a> <a href="http://fnnpharm.com/">tadalafil 2.5 mg in india</a> <a href="http://cialissx.com/">cialis 50mg</a> <a href="http://nfshealth.com/">cost of 500 mg amoxicillin</a>

  11. NickGal NickGal 发布于 2021年4月18日 11:05 #

    <a href="http://npropills.com/">levitra drugstore</a> <a href="http://midviagra.com/">where to buy viagra in south africa</a> <a href="http://azzmeds.com/">tadalafil 20 mg in canada</a> <a href="http://xkeypills.com/">prozac medicine in india</a> <a href="http://phrmviagra.com/">where to buy viagra with paypal</a> <a href="http://cialiszm.com/">rx pharmacy cialis</a>

  12. IvyGal IvyGal 发布于 2021年4月18日 13:41 #

    <a href="http://ordcialis.com/">cialis generic online</a> <a href="http://cialiseti.com/">tadalafil 2.5 mg</a> <a href="http://cialisvm.com/">price of cialis for daily use</a> <a href="http://cialispwr.com/">tadalafil tablets india</a> <a href="http://viagraztab.com/">otc viagra online</a> <a href="http://yestablets.com/">lexapro price south africa</a> <a href="http://cialiscap.com/">cialis cheap india</a> <a href="http://lmopharm.com/">amoxicillin price canada</a> <a href="http://ipillviagra.com/">cheapest price for viagra 100mg</a> <a href="http://cialisbr.com/">cheapest cialis generic</a>

  13. EvaGal EvaGal 发布于 2021年4月18日 13:57 #

    <a href="http://srxstore.com/">vardenafil generic for sale</a>

发表评论