首页 > 解决方案 > 为 ansible 塔生成 oath2 令牌的 Nodejs 脚本

问题描述

如何编写节点 js 脚本为 ansible 塔生成 oauth2 令牌。通过 cli :

curl -u username:password -k -X POST https://<tower-host>/api/v2/tokens/

标签: node.jsoauth-2.0ansibleansible-tower

解决方案


使用 axios ( npm i axios) 脚本是:

var axios = require('axios');
var https = require('https');

const instance = axios.create({
  httpsAgent: new https.Agent({ rejectUnauthorized: false })
});

(async () => {
  var response = await instance({
    method: 'post',
    url: 'https://api/v2/token',
    auth: { username: 'foo', password: 'bar' }
  });
  console.log('response is', response.data);
})();

代理说明


推荐阅读