playbook
一. 参考
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
|
- hosts: zznn tasks:
- name: Install Httpd Server yum: name=httpd state=present - name: Configure Httpd weibsite copy: src=./http.conf.j2 dest=/etc/httpd/conf/httpd.conf backup=yes - name: Configure Httpd Server copy: src=./tt.j2 dest=/var/www/html/tt.html owner=root group=root mode=644 backup=yes - name: Service Httpd Server service: name=httpd state=started enabled=yes - name: Service Firewall Server service: name=firewalld state=started enable=yes - name: Cofigure Firewall server shell: firewall-cmd --permanent --zone=public --add-port=80/tcp
- hosts: 10.0.0.11 tasks:
- name: Install nfs Server yum: name=nfs-utils state=present - name: install rpcbind server yum: name=rpcbind state=present
- name: Create nfs Group group: name=nfs1 gid=666 - name: Create nfs user user: name=nfs1 uid=666 group=666 shell=/sbin/nologin create_home=no
- name: Create file directory file: path=/data state=directory owner=nfs1 group=nfs1 mode=777 recurse=yes
- name: service nfs server service: name=nfs state=started enabled=yes
- hosts: 10.0.0.12 tasks:
- name: create nfs_tt directory file: path=/nfs_tt state=directory mode=777
- name: create nfs server yum: name: nfs state: present
- name: create rpcbind yum: name: rpcbind state: present - name: service nfs server service: name: nfs state: started enabled: yes
- name: client mount nfs server mount: src: 10.0.0.11:/data path: /nfs_tt fstype: nfs opts: defaults state: mounted
- hosts: 10.0.0.12 tasks: - name: install httpd Server yum: name=httpd state=present enablerepo=epel
- name: change index.html copy: src=./httpd.conf dest=/etc/httpd/conf/httpd.conf owner=root group=root mode=644 backup=yes
- name: create tt group group: name=tt gid=7788 state=present
- name: create tt user user: name=tt uid=7788 group=7788 shell=/sbin/nologin create_home=no
- name: systemctl start firewall service: name=firewalld state=started
- name: systemctl start httpd service: name=httpd state=started
- name: kaifang firewall port80 firewalld: zone: public port: 80/tcp permanent: yes immediate: yes state: enabled
- hosts: 10.0.0.11 tasks:
- name: configure welcome-------666--------> > site copy: content: "welcome-------666--------> > " dest: /var/www/html/tt.html owner: root group: root mode: 644
- hosts: 10.0.0.12 tasks: - name: configure welcome-------888--------> > site copy: content: "welcome-------888--------> > " dest: /var/www/html/tt.html owner: root group: root mode: 644
- hosts: 10.0.0.12 tasks:
- name: install httpd server yum: name: httpd,php,php-pdo,php-mbstring,php-gd,firewalld state: present
- name: cofigure file server file: path: /home/gegewu/php state: directory owner: gegewu group: gegewu mode: 644
- name: cofigure firewall port80 firewalld: zone: public permanent: yes immediate: yes port: 80/tcp state: enabled
- name: service start httpd service: name=httpd state=started
- name: configure game.html copy: src=./game.html dest=/var/www/html/game.html owner=root group=root mode=777 backup=yes
- name: copy: src=./index.php dest=/var/www/html/index.php owner=root group=root mode=777 backup=yes
- name: file mode+777 file: path=/var/www/html owner=gegewu group=gegewu mode=777 recurse=yes
- name: get_url: url: http://fj.xuliangwei.com/public/ip.txt dest: /var/www/html/ip.txt backup: yes
- name: file: path=/var/www/html owner=apache group=apache mode=777 recurse=yes
- name: copy kod cloud code unarchive: src=./kodexplorer4.47.zip dest=/var/www/html/ mode=0777
- name: systemctl restart httpd service: name: httpd state: restarted
- hosts: 10.0.0.12 vars: web_packages: httpd ftp_packages: vsftpd
tasks: - name: install rpm packages yum: name={{ web_packages }} state=present
- name: install rpm packages yum: name={{ ftp_pack }} state=present
- hosts: 10.0.0.12 vars: - web_packages: httpd-2.4.6 - ftp_packages: vsftpd-3.0.2
tasks: - name: install {{ web_packages }} {{ ftp_packages }} yum: name: - "{{ web_packages }}" - "{{ ftp_packages }}" state: present
- hosts: 10.0.0.12 vars_files: ./vars_public.yml
tasks: - name: install {{ web_packages }} {{ ftp_packages }} yum: name: - "{{ web_packages }}" - "{{ ftp_packages }}" state: present
web_packages: httpd ftp_packages: vsftpd
- hosts: zznn tasks: - name: install httpd server yum: name=httpd state=present
- name: service start httpd service: name=httpd state=started
- name: check httpd status shell: ps -ef |grep httpd register: check_httpd
- name: status Httpd debug: msg: "{{ check_httpd.stdout_lines }}"
- hosts: zznn tasks: - name: output ansible facts debug: msg: ip address "{{ ansible_fqdn }}" is "{{ ansible_default_ipv4.address }}"
- hosts: zznn tasks:
- name: copy 1.txt template: src: ./1.txt dest: /home/gegewu
- hosts: zznn vars: check_mem: memcached MAXCONN: 2048 tasks: - name: yum yum: name: "{{ check_mem }}" state: present - name: template=copy
template: src: ./memcached.j2 dest: /etc/sysconfig/memcached
- name: service service: name: "{{ check_mem }}" state: restarted
- name: shell shell: ps -ef |grep "{{ check_mem }}" register: check_ps
- name: debug debug: msg: "{{ check_ps.stdout_lines }}"
- hosts: zznn tasks:
- name: shell shell: echo $RANDOM |md5sum |cut -c 5-12 register: get_random
- name: debug debug: msg: "{{ get_random.stdout_lines }}"
- name: hostname hostname: name: "{{ get_random.stdout_lines[0] }}"
- hosts: zznn vars: check_mem: 利用fascts批量修改主机名称 tasks:
- name: hostname hostname: name: "web_{{ ansible_default_ipv4.address }}"
- name: dubug debug: msg: "{{ check_mem }}" - name: debug2 debug: msg: "{{ ansible_default_ipv4.address.split('.')[-1] }}"
- hosts: 10.0.0.11 vars: install_nginx: nginx
tasks: - name: debug debug: msg={{ install_nginx }}
- name: yum yum: name={{ install_nginx }},php,php-pdo,php-gd,php-mbstring,php-fpm state=present
- name: group user: name=www gid=666 state=present
- name: user user: name=www uid=666 gid=666 shell=/sbin/nologin create_home=no - name: copy nginx.conf copy: src=./nginx.j2 dest=/etc/nginx/nginx.conf bakup=yes
- name: copy nginx.conf copy: src=./kod.conf.j2 dest=/etc/nginx/conf.d/kod.conf bakup=yes
- name: create file file: path=ansible_code state=directory
- name: unzip kod date directory unarchive: src=./backup/kodexplorer4.40.zip dest=/ansible_code
- name: chmod kod date www file: path=/ansible_code owner=www group=www recurse=yes mode=0777 - name: cofigure php-FPM server php进程启动个数及每个进程能够接受的链接和请求 copy: src=./php_www.conf.j2 dest=/etc/php-fpm.d/www.cnf
- name: cofigur e php server调整可到云上传大小 copy: src=./php.ini.j2 dest=/etc/php.ini - name: service nginx Server service: name=nginx state=started enable=yes
- name: service nginx Server service: name=php-fpm state=started enable=yes
- hosts: 10.0.0.12 vars: - install_1: /home/gegewu/prometheus.sh - install_2: /home/gegewu/telegraf.sh - install_3: /home/gegewu/alertmanager.sh - tg_alert: /home/gegewu/alertmanager.serivce - tg_n9eserver: /home/gegewu/n9eserver.service - tg_n9eweb: /home/gegewu/n9eweb.service - linux_dir: /opt
tasks:
- name: copy prometheus copy: src="{{ install_1 }}" dest="{{ linux_dir }}" mode=0777
- name: copy telegraf copy: src="{{ install_2 }}" dest="{{ linux_dir }}" mode=0777
- name: copy n9e_5.6 unarchive: src=./n9e.5.6.zip dest="{{ linux_dir }}" mode=0777
- name: copy kod alertmanger copy: src="{{ install_3 }}" dest="{{ linux_dir }}" mode=0777
- name: install mysql shell: apt-get install -y mysql-server-5.7
- name: daoru sql shell: mysql -uroot -p1234 < /opt/n9e-5.6/docker/initsql/a-n9e.sql
- name: restart mysql service: systemctl start mysql - name: systemctl restart mysql service: name: mysql state: restarted
- name: systemctl restart prometheus service: name=prometheus state=restarted
- name: systemctl restart telegraf service: name=telegraf state=restarted
- name: systemctl restart alertmanager service: name=alertmanager state=restarted
- name: start n9eserver shell: nohup ./n9e server &> server.log &
- name: start n9eweb shell: nohup ./n9e webapi &> webapi.log &
- name: firewall prometheus shell: ufw allow 8091
- name: firewall mysql shell: ufw allow 3306
- name: firewall n9eserver shell: ufw allow 19000
- name: firewall n9eweb shell: ufw allow 18000
- name: firewall alertmanager shell: ufw allow 9093
- name: shell shell: echo "构建完成访问:"http://localhost:8091"" register: dh - name: debug debug: msg="{{ web_ip }}"
- hosts: 10.0.0.128 vars: web_server: httpd linux_dir: /home/gegewu/smartping
tasks: - name: file file: path="{{ linux_dir }}" state=directory owner=gegewu group=gegewu mode=777 recurse=yes - name: unarchive unarchive: src=./smartping-v0.8.0.zip dest="{{ linux_dir }}" mode=0777
- name: copy copy: src=./anaconda-ks.cfg dest="{{ linux_dir }}" mode=0777
- name: 8899 firewalld: zone: public permanent: yes immediate: yes port: 8899/tcp state: enabled - name: start shell: /"{{ linux_dir }}/control start"
- name: service service: name=firewalld state=started enabled=yes
- name: web shell: echo "浏览器访问本机ip:8899" register: web_ip - name: debug debug: msg: "{{ web_ip }}"
- hosts: 10.0.0.128 tasks:
- name: install httpd server yum: name: httpd,php,php-pdo,php-mbstring,php-gd,firewalld state: present
- name: cofigure file server file: path: /home/gegewu/php state: directory owner: gegewu group: gegewu mode: 644
- name: cofigure firewall port80 firewalld: zone: public permanent: yes immediate: yes port: 80/tcp state: enabled
- name: service start httpd service: name=httpd state=started
- name: copy: src=./index.php dest=/var/www/html/index.php owner=root group=root mode=777 backup=yes
- name: file mode+777 file: path=/var/www/html owner=gegewu group=gegewu mode=777 recurse=yes
- name: get_url: url: http://fj.xuliangwei.com/public/ip.txt dest: /var/www/html/ip.txt backup: yes
- name: file file: path=/var/www/html owner=apache group=apache mode=777 recurse=yes
- name: unarche unarchive: src=./kodexplorer4.47.zip dest=/var/www/html/ mode=0777
- name: systemctl restart httpd service: name: httpd state: restarted
ansible 10.0.0.12 -m mount -a "src=10.0.0.11:/data path=/nfs_tt fstype=nfs opts=defaults state=mounted " -i hosts
|
bootstrap.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| - name: Install dependencies hosts: all remote_user: root tasks: - name: Make sure the hostname is correct hostname: name: '{{ inventory_hostname }}' - name: Install required packages yum: name: - yum-utils - device-mapper-persistent-data - lvm2 - git - ansible state: present - name: Add docker-ce repository yum_repository: name: docker-ce-stable description: Docker CE Stable repo baseurl: http://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/stable gpgkey: http://mirrors.aliyun.com/docker-ce/linux/centos/gpg - name: Install docker-ce yum: name=docker-ce state=present - name: Start docker service: name=docker state=started - name: Config registry copy: content: '{ "insecure-registries" : ["0.0.0.0/0"] }' dest: /etc/docker/daemon.json notify: - restart docker - name: pip install docker pip: name: docker handlers: - name: restart docker service: name=docker state=restarted - name: Config control nodes hosts: control remote_user: root tasks: - name: Copy hosts copy: src: /etc/hosts dest: /etc/hosts
|
centos-deploy.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| - name: Deploy hosts: all remote_user: root tasks: - name: Copy bootstrap playbook copy: src: ./kolla_bootstrap.yml dest: /root/bootstrap.yml - name: Install required packages yum: name: - yum-utils - device-mapper-persistent-data - lvm2 - git - ansible state: present - name: Add docker-ce repository yum_repository: name: docker-ce-stable description: Docker CE Stable repo baseurl: https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/stable gpgkey: https://mirrors.aliyun.com/docker-ce/linux/centos/gpg - name: install docker-ce yum: name=docker-ce state=present - name: Start docker service: name=docker state=started - name: install pip yum: name=python-pip state=present - name: pip install kolla-ansible pip: name: kolla-ansible - name: Start docker registry docker_container: name: registry restart_policy: always image: registry:2 ports: - 4000:5000 volumes: - registry:/var/lib/registry env: REGISTRY_PROXY_REMOTEURL: "https://registry.cn-shanghai.aliyuncs.com"
- name: Init kolla-ansible shell: | mkdir -p /etc/kolla cp /usr/share/kolla-ansible/etc_examples/kolla/* /etc/kolla/ cp /usr/share/kolla-ansible/ansible/inventory/* ~/ kolla-genpwd - name: Copy bootstrap playbook copy: src: ./kolla_bootstrap.yml dest: /root/bootstrap.yml
handlers: - name: restart docker service: name=docker state=restarted
|
ubuntu-deploy.yml
其中docker-ce
需要手动安装详见aliyun
镜像栈
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| - name: Deploy hosts: all remote_user: root tasks: - name: Copy bootstrap playbook copy: src: ./kolla_bootstrap.yml dest: /root/bootstrap.yml - name: Install required packages apt: name: - lvm2 - git - ansible - apt-transport-https - ca-certificates - curl - software-properties-common state: present - name: install docker-ce apt: name=docker-ce state=present - name: Start docker service: name=docker state=started - name: install pip apt: name=python-pip state=present - name: pip install kolla-ansible pip: name: kolla-ansible - name: Start docker registry docker_container: name: registry restart_policy: always image: registry:2 ports: - 4000:5000 volumes: - registry:/var/lib/registry env: REGISTRY_PROXY_REMOTEURL: "https://registry.cn-shanghai.aliyuncs.com"
- name: Init kolla-ansible shell: | mkdir -p /etc/kolla cp /usr/local/share/kolla-ansible/etc_examples/kolla/* /etc/kolla/ cp /usr/local/share/kolla-ansible/ansible/inventory/* ~/ kolla-genpwd - name: Copy bootstrap playbook copy: src: ./kolla_bootstrap.yml dest: /root/bootstrap.yml
handlers: - name: restart docker service: name=docker state=restarted
|