ansible-playbook nodejs

7316 ワード


=====ansible-go tree=====
tree ansible-go -L 2

ansible-go
├── ansible.cfg
├── docs
│   └── ansible-install
├── examples
│   ├── ansible.cfg
│   ├── group_vars
│   ├── inventory
│   └── playbooks
├── roles
│   ├── apache
│   ├── appserver
│   ├── aws
│   ├── aws_ec2
│   ├── galaxy
│   ├── geoipupdate
│   ├── haproxy
│   ├── innodb_data_restore
│   ├── keepalived
│   ├── mysql
│   ├── mysqlcluster
│   ├── ndbcluster_data_restore
│   ├── node.4dfornine99
│   ├── node.backcall
│   ├── node.bigtwo_p2p
│   ├── node.bigtwo_webonline
│   ├── node.daemon
│   ├── node.fbsse
│   ├── node.flashgame_security
│   ├── nodejs10
│   ├── nodejs7
│   ├── node.ncpay_grabber
│   ├── node.ncpay_rpm
│   ├── node.ncpay_transferin
│   ├── node.ncpay_transferout
│   ├── node.nodegrabasc_bot
│   ├── node.p2p_bot
│   ├── node.rocketchat
│   ├── node.spay_daemon
│   ├── php
│   ├── proxmox
│   ├── redis
│   ├── repo-epel
│   ├── repo-ius
│   ├── selinux
│   ├── system.chrony
│   ├── system.common
│   ├── system.files
│   ├── system.firewalld
│   ├── system.hostname
│   ├── system.hosts
│   ├── system.ntpd
│   ├── system.packages
│   ├── system.resolv_conf
│   ├── system.rsync
│   ├── system.rsyslog
│   ├── system.services
│   ├── system.snmp
│   ├── system.sshd
│   ├── system.sysctl
│   ├── system.timezone
│   ├── system.update
│   └── zabbix-agent
├── staging
    ├── ansible.cfg
    ├── docker-containers
    ├── group_vars
    ├── inventory
    ├── inventory-gwj
    └── playbooks
    
    
=====  role  node.ncpay_transferin=====
ls roles/node.ncpay_transferin/
defaults        ,       
tasks       role       
templates       ,      

=====  defaults=====
vi roles/node.ncpay_transferin/defaults/main.yml 

---
ncpay_transferin_files:
  - [email protected]
  - ncpay-transferin.target

ncpay_transferin_services:
  - ncpay-transferin.target
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]
  - [email protected]


=====  tasks=====
vi roles/node.ncpay_transferin/tasks/main.yml

---
- name: copy transferin file
  template:
    src: "templates/{{ item }}"
    dest: /etc/systemd/system/
  with_items: "{{ ncpay_transferin_files }}"

- name: ncpay transferin start and enable
  service:
    name: "{{ item }}"
    state: started
    enabled: yes
  with_items: "{{ ncpay_transferin_services }}"


=====   templates=====
vi roles/node.ncpay_transferin/templates/[email protected]

[Unit]
Description=NodeJS Ncpay Transferin Bot 
Requires=network.target 
After=syslog.target network.target 

PartOf=ncpay-transferin.target
[Service]
ExecStartPre=/bin/sh -c "echo PUBLIC_PORT=`expr 20000 + %i` >> /run/ncpay-transferin-%i.env"
ExecStartPre=/bin/sh -c "echo INTERNAL_PORT=`expr 20000 + %i` >> /run/ncpay-transferin-%i.env"
ExecStopPost=/bin/rm /run/ncpay-transferin-%i.env
EnvironmentFile=-/run/ncpay-transferin-%i.env
ExecStart=/usr/bin/node /var/nodejs/bank-scripts/index.js 
ExecStop=/bin/kill -SIGTERM $MAINPID 
TimeoutStopSec=360s 
StandardOutput=syslog 
StandardError=syslog 
SyslogIdentifier=NodeJS ncpay-transferin-%i
User=root
Group=root 
KillSignal=SIGTERM 
KillMode=mixed 
Restart=on-failure 
RestartSec=10
StartLimitInterval=30s 
StartLimitBurst=2 
Environment=NODE_ENV=staging 
Environment=ROBOTID=%i 
Environment=ROBOTTYPE=4
Environment=APP_NAME=ncpay 
Environment=SERVERID=1
Environment=XVFBSERVERNUM=%i
Environment=INTERNAL_IP=xxxxx
Environment=PUBLIC_IP=xxxx
Environment=ROOTDIR=/var/nodejs/bank-customer-transferin/ 
Environment=NODE_PATH=/usr/lib/node_modules 
[Install] 
WantedBy=ncpay-transferin.target


vi roles/node.ncpay_transferin/templates/ncpay-transferin.target 

[Unit]
Description=NodeJS NCPAY transferin target allowing to start/stop all [email protected] instances at once
PartOf=ncpay.target
[Install]
WantedBy=multi-user.target ncpay.target



=====  host=====
vi ansible-go/staging/inventory

[nodejs_ncpay]
x.x.x.x



=====  playbook         ,  role=====
vi staging/playbooks/nodejs_ncpay.yaml

- hosts: nodejs_ncpay
  vars:
    update_system: yes
    common_timezone: Asia/Kuala_Lumpur
    hostname: nodejs_ncpay
    firewalld_rich_rules:
      - rule: rule family="ipv4" source address="10.1.0.0/16" port port="0-65535" protocol="tcp" accept
      - rule: rule family="ipv4" source address="10.0.1.0/24" port port="18000-19999" protocol="tcp" accept
      - rule: rule family="ipv4" source address="10.10.1.0/24" accept
      - rule: rule family="ipv4" source address="0.0.0.0/0" port port="30001-40000" protocol="tcp" accept
      - rule: rule family="ipv4" source address="0.0.0.0/0" port port="50001-60000" protocol="tcp" accept
      - rule: rule family="ipv4" source address="0.0.0.0/0" port port="59000-59009" protocol="tcp" accept
    nodejs_npm_global_packages:
      - name: aws-sdk
        version: 2.395.0
      - name: debug
        version: 4.1.1
      - name: iconv-lite
        version: 0.4.19
      - name: jimp
        version: 0.3.7
      - name: koa-router
        version: 8.0.8
      - name: mysql
        version: 2.13.0
      - name: request
        version: 2.88.2
      - name: underscore
        version: 1.8.3
    nodejs_npm_global_unsafe_packages:
      - name: nightmare
        version: 2.10.0
  roles:
    - system.update
    - system.sshd
    - system.hostname
    - system.timezone
    - system.common
    - system.packages
    - system.rsync
    - system.firewalld
    - system.snmp
    - system.rsyslog
    - system.sysctl
    - system.chrony
    - zabbix-agent
    - nodejs10
    - node.daemon
    - node.ncpay_rpm
    - node.ncpay_grabber
    - node.ncpay_transferin
    - node.ncpay_transferout


=====  playbook=====
cd ansible-go/staging
ansible-playbook -i inventory playbooks/nodejs_ncpay.yaml