我正在尝试为批量用户更改密码。通过vars提供用户名时,脚本不起作用。我收到以下错误 错误!加载YAML时的语法错误。 找到了不可接受的密钥(无法哈希的类型:“ AnsibleMapping”)
这是脚本
const AWS = require('aws-sdk');
var cred = new AWS.CredentialProviderChain();
var sts = new AWS.STS({credentials: cred, region: 'us-east-1'});
var crd2 ;
var params = {
RoleArn: "arn:aws:iam::123456789012:role/crossAccount",
RoleSessionName: "atul"
};
sts.assumeRole(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else {
crd2 = data; // successful response
console.log("Role assured");
}
});
const dynamodb = new AWS.DynamoDB({apiVersion: '2012-08-10', credentials: crd2, region: 'eu-west-1', endpoint: 'https://dynamodb.eu-west-1.amazonaws.com'});
exports.handler = (event, context, callback) => {
console.log(crd2);
console.log("**** " + JSON.stringify(dynamodb));
dynamodb.getItem({
TableName: "Testing",
Key: {
"Id": {
S: "1121091591"
}
}
}, function(err, data) {
if (err) {
console.log(err, err.stack);
callback(null, {
statusCode: '500',
body: err
});
} else {
console.log(data);
callback(null, {
statusCode: '200',
body: 'Hello '
});
}
})
};
答案 0 :(得分:1)
在下面使用。使用-您实际上已将用户定义为列表而不是var,我从变量test中删除了-前缀。另外,“”之间的行也被视为单个命令,因此请始终在“”之间定义命令。
取消了对用户名的检查,因为它不需要,名称模块具有名为state的属性,该属性将检查并执行在该状态中声明的操作。
- name: Set Password
hosts: localhost
become: yes
ignore_errors: yes
vars:
users:
test
tasks:
- name: Change Password
user:
name: "{{ users }}"
password: "$1$Du3HGfHV$ny91hdJz81y.NtKw/"
update_password: always
state: present