问题描述
当前,我们成功在AWS域中使用打包程序(位于Azure DevOps中的构建管道中)部署映像。现在我们想更进一步,我们正在尝试为将来的Ansible维护配置几个用户。因此,我们编写了一个脚本并将其作为内联Powershell脚本进行了尝试,但是这两个选项似乎都无法使用Azure DevOps变量组中设置的变量,所有其他变量都已成功使用。我的代码如下:
{
"variables": {
"build_version": "{{isotime \"2006.01.02.150405\"}}","aws_access_key": "$(aws_access_key)","aws_secret_key": "$(aws_secret_key)","region": "$(region)","vpc_id": "$(vpc_id)","subnet_id": "$(subnet_id)","security_group_id": "$(security_group_id)","VagrantUserpassword": "$(VagrantUserPassword)"
},"builders": [
{
"type": "amazon-ebs","access_key": "{{user `aws_access_key`}}","secret_key": "{{user `aws_secret_key`}}","region": "{{user `region`}}","vpc_id": "{{user `vpc_id`}}","subnet_id": "{{user `subnet_id`}}","security_group_id": "{{user `security_group_id`}}","source_ami_filter": {
"filters": {
"name": "Windows_Server-2016-English-Full-Base-*","root-device-type": "ebs","virtualization-type": "hvm"
},"most_recent": true,"owners": [
"801119661308"
]
},"ami_name": "WIN2016-CUSTOM-{{user `build_version`}}","instance_type": "t3.xlarge","user_data_file": "userdata.ps1","associate_public_ip_address": true,"communicator": "winrm","winrm_username": "Administrator","winrm_timeout": "15m","winrm_use_ssl": true,"winrm_insecure": true,"ssh_interface": "private_ip"
}
],"provisioners": [
{
"type": "powershell","environment_vars": ["VagrantUserPassword={{user `VagrantUserPassword`}}"],"inline": [
"Install-WindowsFeature web-server,web-webserver,web-http-logging,web-stat-compression,web-dyn-compression,web-asp-net,web-mgmt-console,web-asp-net45","New-LocalUser -UserName 'Vagrant' -Description 'User is responsible for Ansible connection.' -Password '$(VagrantUserPassword)'"
]
},{
"type": "powershell","scripts": [
"scripts/DisableUAC.ps1","scripts/iiscompression.ps1","scripts/ChocoPackages.ps1","scripts/PrepareAnsibleUser.ps1"
]
},{
"type": "windows-restart","restart_check_command": "powershell -command \"& {Write-Output 'Machine restarted.'}\""
},"inline": [
"C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Scripts\\InitializeInstance.ps1 -Schedule","C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Scripts\\SysprepInstance.ps1 -NoShutdown"
]
}
]
}
“ VagrantUserpassword”:“ $(VagrantUserPassword)”不起作用,我们尝试了多个选项,但似乎都不起作用。
有什么主意吗?
亲切的问候,
里克。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)