node-ansible icon indicating copy to clipboard operation
node-ansible copied to clipboard

node-ansible have any default time out process.

Open Git-Rajkumar opened this issue 7 years ago • 0 comments

I am working on to develop Node+ ansible Module, I need to build mysql docker image via ansible script. while i building image request calling multiple time, if request get second time browser goes to connection was reset.

Note: If second time request build image perfectly. First request only issue, at same time browser goes connection was reset.

What i did:

mysql.js:

  var express = require('express');
  var path = require('path');
  var favicon = require('serve-favicon');
  var logger = require('morgan');
  var bodyParser = require('body-parser');
  var app = express();
  var Ansible = require('node-ansible');
  var yaml = require('node-yaml');
  var timeout = require('infinite-timeout');
  // view engine setup
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'ejs');
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({extended: false}));
  app.use(express.static(path.join(__dirname, 'public')));

  //app.use('/', index.jade);
  app.get('/', function (req, res) {
      tmp = "";

      console.log(req.url);

      res.render('index', {title: ' Mysql Setup'})
  });

  var tmp = "";
  var postcount;
  app.post('/setup', function (req, res) {

      postcount = Object.keys(req.body).length
      console.log(postcount);

      console.log(req.url);

      for (var key in req.body) {

          console.log(req.body[key]);

          if (req.body[key] == "mysql") {


              console.log("within mysql");

              var playbook = new Ansible.Playbook().playbook("mysql");

              playbook.on('stdout', function (data) {
                  console.log(data.toString());
              });
              playbook.on('stderr', function (data) {
                  console.log(data.toString());
              });

              var command = playbook.inventory('inventories/Mysql/hosts').verbose('v');

              var promise = command.exec();
              
              promise.then(function (successResult) {
                  console.log("within mysql sucess");
                  tmp += "Build Mysql Image  Process";
                  tmp += successResult.output;
                  res.render('mysql_build_result', {data: tmp, title: 'Mysql Image Build Result'});

              }, function (error) {
                  tmp += error;
                  console.log("within mysql error");
                  res.render('mysql_build_result', {data: tmp, title: 'Mysql Image Build Result Error'});
              });

              return;
          }else
          {
              console.log("No Request are matched");
          }

      }
  });

  var server = app.listen(3030, function () {

      var host = server.address().address
      var port = server.address().port

      console.log("Example app listening at http://%s:%s", host, port);
  });

Ansible Script:

mysql.yml

   ---

      - name: Creates directory
        file: path=/opt/mysql state=directory owner=root group=root  mode=0775

      - name: Install Docker py
        command: pip install docker-py

      - name: Copy Docker Files to  Remote machine
        synchronize: mode=push  src=/var/www/html/nodeapp/dockerfiles  dest=/opt/mysql/

      - name: Build Mysql image and with buildargs
        docker_image: >
           path=/opt/mysql/dockerfiles/mysql
           name=mysql_node
           tag=mysql_node
           state=present

Ansible Log:

    Example app listening at http://:::3030
    /
    1
    /setup
    mysql
    within mysql
    Using /etc/ansible/ansible.cfg as config file


    PLAY [webservers] **************************************************************


    TASK [Gathering Facts] *********************************************************

    ok: [192.168.1.101]


    TASK [mysql : Creates directory] ***********************************************

    ok: [192.168.1.101] => {"changed": false, "gid": 0, "group": "root", "mode": "0775", "owner": "root", "path": "/opt/magento2", "size": 4096, "state": "directory", "uid": 0}


    TASK [mysql : Install Docker py] ***********************************************

    changed: [192.168.1.101] => {"changed": true, "cmd": ["pip", "install", "docker-py"], "delta": "0:00:00.283441", "end": "2017-08-02 15:34:55.003891", "rc": 0, "start": "2017-08-02 15:34:54.720450", "stderr": "You are using pip version 8.1.1, however version 9.0.1 is available.\nYou should consider upgrading via the 'pip install --upgrade pip' command.", "stderr_lines": ["You are using pip version 8.1.1, however version 9.0.1 is available.", "You should consider upgrading via the 'pip install --upgrade pip' command."], "stdout": "Requirement already satisfied (use --upgrade to upgrade): docker-py in /usr/lib/python2.7/site-packages\nRequirement already satisfied (use --upgrade to upgrade): requests>=2.5.2 in /usr/lib/python2.7/site-packages (from docker-py)\nRequirement already satisfied (use --upgrade to upgrade): six>=1.4.0 in /usr/lib/python2.7/site-packages (from docker-py)\nRequirement already satisfied (use --upgrade to upgrade): websocket-client>=0.32.0 in /usr/lib/python2.7/site-packages (from docker-py)\nRequirement already satisfied (use --upgrade to upgrade): urllib3==1.15.1 in /usr/lib/python2.7/site-packages (from requests>=2.5.2->docker-py)", "stdout_lines": ["Requirement already satisfied (use --upgrade to upgrade): docker-py in /usr/lib/python2.7/site-packages", "Requirement already satisfied (use --upgrade to upgrade): requests>=2.5.2 in /usr/lib/python2.7/site-packages (from docker-py)", "Requirement already satisfied (use --upgrade to upgrade): six>=1.4.0 in /usr/lib/python2.7/site-packages (from docker-py)", "Requirement already satisfied (use --upgrade to upgrade): websocket-client>=0.32.0 in /usr/lib/python2.7/site-packages (from docker-py)", "Requirement already satisfied (use --upgrade to upgrade): urllib3==1.15.1 in /usr/lib/python2.7/site-packages (from requests>=2.5.2->docker-py)"]}


    TASK [mysql : Copy Docker Files to  Remote machine] ****************************

    [email protected]'s password: 
    ok: [192.168.1.101] => {"changed": false, "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh=/usr/bin/ssh -S none -o StrictHostKeyChecking=no --out-format=<<CHANGED>>%i %n%L /var/www/html/nodeapp_completed/dockerfiles [email protected]:/opt/magento2/", "msg": "", "rc": 0, "stdout_lines": []}


    TASK [mysql : Build Mysql image and with buildargs] ****************************

    1
    /setup
    mysql
    within mysql
    Using /etc/ansible/ansible.cfg as config file


    PLAY [webservers] **************************************************************


    TASK [Gathering Facts] *********************************************************

    ok: [192.168.1.101]


    TASK [mysql : Creates directory] ***********************************************

    ok: [192.168.1.101] => {"changed": false, "gid": 0, "group": "root", "mode": "0775", "owner": "root", "path": "/opt/magento2", "size": 4096, "state": "directory", "uid": 0}


    TASK [mysql : Install Docker py] ***********************************************

    changed: [192.168.1.101] => {"changed": true, "cmd": ["pip", "install", "docker-py"], "delta": "0:00:00.299737", "end": "2017-08-02 15:36:55.195024", "rc": 0, "start": "2017-08-02 15:36:54.895287", "stderr": "You are using pip version 8.1.1, however version 9.0.1 is available.\nYou should consider upgrading via the 'pip install --upgrade pip' command.", "stderr_lines": ["You are using pip version 8.1.1, however version 9.0.1 is available.", "You should consider upgrading via the 'pip install --upgrade pip' command."], "stdout": "Requirement already satisfied (use --upgrade to upgrade): docker-py in /usr/lib/python2.7/site-packages\nRequirement already satisfied (use --upgrade to upgrade): requests>=2.5.2 in /usr/lib/python2.7/site-packages (from docker-py)\nRequirement already satisfied (use --upgrade to upgrade): six>=1.4.0 in /usr/lib/python2.7/site-packages (from docker-py)\nRequirement already satisfied (use --upgrade to upgrade): websocket-client>=0.32.0 in /usr/lib/python2.7/site-packages (from docker-py)\nRequirement already satisfied (use --upgrade to upgrade): urllib3==1.15.1 in /usr/lib/python2.7/site-packages (from requests>=2.5.2->docker-py)", "stdout_lines": ["Requirement already satisfied (use --upgrade to upgrade): docker-py in /usr/lib/python2.7/site-packages", "Requirement already satisfied (use --upgrade to upgrade): requests>=2.5.2 in /usr/lib/python2.7/site-packages (from docker-py)", "Requirement already satisfied (use --upgrade to upgrade): six>=1.4.0 in /usr/lib/python2.7/site-packages (from docker-py)", "Requirement already satisfied (use --upgrade to upgrade): websocket-client>=0.32.0 in /usr/lib/python2.7/site-packages (from docker-py)", "Requirement already satisfied (use --upgrade to upgrade): urllib3==1.15.1 in /usr/lib/python2.7/site-packages (from requests>=2.5.2->docker-py)"]}


    TASK [mysql : Copy Docker Files to  Remote machine] ****************************

    [email protected]'s password: changed: [192.168.1.101] => {"actions": ["Built image m2_node_mysql_test2:m2_node_mysql_test from /opt/magento2/dockerfiles/mysql"], "changed": true, "image": {"Architecture": "amd64", "Author": "", "Comment": "", "Config": {"ArgsEscaped": true, "AttachStderr": false, "AttachStdin": false, "AttachStdout": false, "Cmd": ["mysqld"], "Domainname": "", "Entrypoint": ["docker-entrypoint.sh"], "Env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "GOSU_VERSION=1.7", "MYSQL_MAJOR=5.6", "MYSQL_VERSION=5.6.37-1debian8"], "ExposedPorts": {"3306/tcp": {}}, "Hostname": "e24d0b5cccc1", "Image": "sha256:f64009628a0687e7e0c9de22b2c952bd5941cb401cf04375e06bb8af874c99ec", "Labels": {}, "OnBuild": [], "OpenStdin": false, "StdinOnce": false, "Tty": false, "User": "", "Volumes": {"/var/lib/mysql": {}}, "WorkingDir": ""}, "Container": "4be9441de29b690f8a7462c25c00290f89a2b01dfc110c09039140fae5f5e530", "ContainerConfig": {"ArgsEscaped": true, "AttachStderr": false, "AttachStdin": false, "AttachStdout": false, "Cmd": ["/bin/sh", "-c", "#(nop) CMD [\"mysqld\"]"], "Domainname": "", "Entrypoint": ["docker-entrypoint.sh"], "Env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "GOSU_VERSION=1.7", "MYSQL_MAJOR=5.6", "MYSQL_VERSION=5.6.37-1debian8"], "ExposedPorts": {"3306/tcp": {}}, "Hostname": "e24d0b5cccc1", "Image": "sha256:f64009628a0687e7e0c9de22b2c952bd5941cb401cf04375e06bb8af874c99ec", "Labels": {}, "OnBuild": [], "OpenStdin": false, "StdinOnce": false, "Tty": false, "User": "", "Volumes": {"/var/lib/mysql": {}}, "WorkingDir": ""}, "Created": "2017-08-02T10:11:19.0629579Z", "DockerVersion": "1.10.3", "GraphDriver": {"Data": {"DeviceId": "3802", "DeviceName": "docker-253:3-11010052-8754256fd7cbda0fae8764a69bbeac1514463cfb85e7b7aff8ae2423195037b9", "DeviceSize": "10737418240"}, "Name": "devicemapper"}, "Id": "sha256:0d685cb2955e52f7fc67f1423d6e1f18b76036dfdbc3781edd9ca01fb227cd39", "Os": "linux", "Parent": "sha256:f64009628a0687e7e0c9de22b2c952bd5941cb401cf04375e06bb8af874c99ec", "RepoDigests": [], "RepoTags": ["m2_node_mysql_test2:m2_node_mysql_test"], "Size": 298292364, "VirtualSize": 298292364}}


    PLAY RECAP *********************************************************************

    192.168.1.101              : ok=5    changed=2    unreachable=0    failed=0   



    within mysql sucess

Suggest Me What Wrong in my code. Why command.exec(); function to recall new request and build new docker image.

Is there any default time out for first request, if there, how to reset this.

Note: My ansible script to take minimun 20 min to execute the process.

Git-Rajkumar avatar Aug 03 '17 10:08 Git-Rajkumar