{"rsdb":{"rid":"377691","subhead":"","postdate":"0","aid":"264257","fid":"97","uid":"1","topic":"1","content":"
\n

1.\u4ec0\u4e48\u662fplaybook<\/strong><\/h3> \n
    \n
  • playbook :\u5b9a\u4e49\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\uff0c\u4ee5yml\u4e3a\u540e\u7f00\u7ed3\u5c3e\uff0c\u90a3playbook\u7ec4\u6210\u5982\u4e0b\u3001<\/strong><\/li> \n
  • play\uff1a\u5b9a\u4e49\u7684\u662f\u4e3b\u673a\u7684\u89d2\u8272<\/strong><\/li> \n
  • task: \u5b9a\u4e49\u7684\u662f\u5177\u4f53\u6267\u884c\u7684\u4efb\u52a1<\/strong><\/li> \n
  • \u603b\u7ed3\uff1aplaybook\u662f\u7531\u4e00\u4e2a\u6216\u591a\u4e2aplay\u7ec4\u6210\uff0c\u4e00\u4e2aplay\u53ef\u4ee5\u5305\u542b\u591a\u4e2atask\u4efb\u52a1\u3002<\/strong><\/li> \n
  • \u53ef\u4ee5\u7406\u89e3\u4e3a\uff1a\u4f7f\u7528\u4e0d\u540c\u7684\u6a21\u5757\u6765\u5171\u540c\u5b8c\u6210\u4e00\u4ef6\u4e8b\u60c5<\/strong><\/li> \n <\/ul> \n

    playbook \u5267\u672c<\/strong> <---------\u6587\u4ef6 YAML<\/strong><\/p> \n

      \n
    • play \u627e\u8c01<\/strong> <----------\u627e\u90a3\u4e2a\u4e3b\u673a web01<\/strong><\/li> \n
    • task \u505a\u4ec0\u4e48<\/strong> <----------- \u5e72\u4ec0\u4e48\u4e8b\u60c5<\/strong> yum copy service<\/strong><\/li> \n <\/ul> \n

      2.playbook\u548cAD-HOc\u533a\u522b<\/strong><\/h3> \n
        \n
      • playbook \u662f\u5bf9AD-HOC \u7684\u4e00\u79cd\u7f16\u6392\u65b9\u5f0f<\/strong><\/li> \n
      • playbook \u53ef\u4ee5\u6301\u4e45\u8fd0\u884c\uff0c\u800cAD-HOC \u53ea\u80fd\u4e34\u65f6\u8fd0\u884c<\/strong><\/li> \n
      • playbook \u9002\u5408\u590d\u6742\u4efb\u52a1\uff0c\u800cAD-HOC\u9002\u5408\u505a\u7b80\u5355\u7684\u4efb\u52a1<\/strong><\/li> \n
      • playbook\u80fd\u63a7\u5236\u4efb\u52a1\u6267\u884c\u7684\u5148\u540e\u987a\u5e8f<\/strong><\/li> \n <\/ul> \n

        3.playbook \u4e09\u677f\u65a7<\/strong> \uff1f \u7f29\u8fdb \u5192\u53f7 \u77ed\u6a2a\u7ebf<\/strong>\uff08\u8bed\u6cd5\u683c\u5f0f\uff09<\/strong><\/h3> \n \n \n \n \n \n \n \n
        \u8bed\u6cd5<\/strong><\/th> \n \u63cf\u8ff0<\/strong><\/th> \n <\/tr> \n <\/thead> \n
        \u7f29\u8fdb<\/strong><\/td> \n YAML \u4f7f\u7528\u56fa\u5b9a\u7684\u7f29\u8fdb\u98ce\u683c\u8868\u793a\u5c42\u7ea7\u7ed3\u6784\uff0c\u6bcf\u4e2a\u7f29\u8fdb\u7531\u4e24\u4e2a\u7a7a\u683c\u7ec4\u6210\uff0c\u4e0d\u80fd\u4f7f\u7528tabs<\/strong><\/td> \n <\/tr> \n
        \u5192\u53f7<\/strong><\/td> \n \u4ee5\u5192\u53f7\u7ed3\u5c3e\u7684\u9664\u5916\uff0c\u5176\u4ed6\u6240\u6709\u5192\u53f7\u540e\u9762\u6240\u6709\u5fc5\u987b\u6709\u7a7a\u683c<\/strong><\/td> \n <\/tr> \n
        \u77ed\u6a2a\u7ebf<\/strong><\/td> \n \u8868\u793a\u5217\u8868\u9879\uff0c\u4f7f\u7528\u4e00\u4e2a\u77ed\u6a2a\u7ebf\u52a0\u4e00\u4e2a\u7a7a\u683c\uff0c\u591a\u4e2a\u9879\u4f7f\u7528\u540c\u6837\u7684\u7f29\u8fdb\u7ea7\u522b\u4f5c\u4e3a\u540c\u4e00\u5217\u8868<\/strong><\/td> \n <\/tr> \n <\/tbody> \n <\/table> \n
          \n
        • \u793a\u4f8b<\/strong> \u5728\/tmp \u76ee\u5f55\u4e0b\u521b\u5efa123.txt \u5c5e\u4e3b root \u5c5e\u7ec4 root \u6743\u96500600<\/strong><\/li> \n <\/ul> \n
          - hosts: webservers\n  tasks:\n    - name: create New File\n      file: path=\/tmp\/123.txt state=touch  owner=root group=root mode=0600\n    - name: create New File2\n      file:\n        path: \/tmp\/789.txt\n        state: touch\n        owner: root\n        group: root\n        mode: 0666\n<\/code><\/pre> \n 
          [root@m01 project]# ansible-playbook  --syntax f1.yml  -i hosts\n \u6d4b\u8bd5\u4ee3\u7801\u662f\u5426\u6b63\u786e<\/code><\/pre> \n 
          ansible-playbook -C f1.yml -i hosts\n\u6d4b\u8bd5\u73af\u5883<\/code><\/pre> \n 

          4.playbook \u5199\u670d\u52a1 \uff08NFS HTTPD Nginx LAMP\uff09<\/strong><\/h3> \n
            \n
          • \u6848\u5217\u4e00 \u4f7f\u7528ansible playbook\u5b89\u88c5\u5e76\u914d\u7f6enfs\u670d\u52a1<\/strong><\/li> \n <\/ul> \n
            #172.16.1.31  nfs\n#172.16.1.7   server\n#172.16.1.8   cliniet\n\n \n#1. \u65b0\u589e\u4e00\u53f0nfs\u670d\u52a1\u5668\nvim .\/project\/hosts\n[webservers]\n172.16.1.7\n172.16.1.8\n\n[nfsservers]\n172.16.1.31\n[root@m01 project]# ssh-copy-id -i ~\/.ssh\/id_rsa.pub root@172.16.1.41\n\n#2. \u6d4b\u8bd5\u4e09\u53f0\u4e3b\u673a\u662f\u5426\u901a\n[root@m01 project]# ansible all -m ping -i hosts\n#3.\u7f16\u5199\u4e00\u4e2anfs-sever\u7684yml\n1. \u5b89\u88c5nfs      yum\n2. \u914d\u7f6enfs      copy\n3.\u521d\u59cb\u5316\u73af\u5883     \n        \u7528\u6237      group user \n        \u76ee\u5f55      file\n        \u6388\u6743      file\n4. \u542f\u52a8\u670d\u52a1        systemd\n[root@m01 project]# cat backup\/nfs_server.yml \n- hosts:  nfsservers\n  tasks:\n    - name:  installed nfs server\n      yum:\n        name:  nfs-utils\n        state:  present\n        \n    - name:  configure nfs server\n      copy:  \n        src:  .\/file\/exports.j2\n        dest:  \/etc\/exports\n        owner:  root\n        group:  root\n        mode:  0644\n        backup:  yes\n        \n    - name:  create nfs group www\n      group:  \n        name:  www\n        gid:  666\n\n    - name:   create nfs user www  \n      user:  \n        name:  www\n        group:  www\n        uid:  666\n        create_home:  no\n        shell:  \/sbin\/nologin\n        \n    - name:  create  nfs directory \n      file:\n        path:  \/ansible_data\n        state:  directory\n        owner:  www\n        group:  www\n        mode:  0755\n        recurse:  yes\n        0\n    - name:  systemd nfs server\n      systemd:\n        name:  nfs\n        state:  restarted\n        enabled:  yes       \n\nscp -rp \/etc\/exports root@172.16.1.61 :\/root\/project\/file\/exports.j2\n#4.\u7f16\u5199\u4e00\u4e2anfs-client\u7684yml\n[root@m01 project]# vim backup\/nfs_client.yml \n\n- hosts:  webservers\n  tasks:\n    - name:  mount nfs server server share directory\n      mount:\n        src:  172.16.1.31:\/ansible_data\n        path:  \/mnt\n        fstype:  nfs\n        opts:  defaults\n        state:  mounted\n                         \n<\/code><\/pre> \n