Using Packer to build an AMI based on Windows Server 2019, and Ansible as provisioner.
This is the provisioners
part of my packer-build.json
:
"provisioners": [
{
"type": "ansible",
"playbook_file": "./provisioners/ansible/ansible_playbook.yml",
"user": "Administrator",
"use_proxy": false,
"extra_arguments": ["-e", "ansible_winrm_server_cert_validation=ignore"]
}
]
This is my ansible_playbook.yml
:
---
- name: Jenkins node playbook
hosts: all
tasks:
- include_tasks: update_system.yml
- include_tasks: install_dependencies.yml
- include_tasks: create_user.yml
I can confirm that at least update_system.yml
and install_dependencies.yml
run successfully.
This is my create_user.yml
:
---
- name: Ensure user jenkins is present
ansible.windows.win_user:
name: jenkins
password: ***REDACTED***
state: present
groups:
- Users
.
.
.
I get an error at this point:
amazon-ebs: TASK [Ensure user jenkins is present] ******************************************
amazon-ebs: fatal: [default]: UNREACHABLE! => {"changed": false, "msg": "basic: Illegal operation attempted on a registry key that has been marked for deletion. (extended fault data: {'transport_message': 'Bad HTTP response returned from server. Code 500', 'http_status_code': 500, 'wsmanfault_code': '2147943418', 'fault_code': 's:Receiver', 'fault_subcode': 'w:InternalError'})", "unreachable": true}
Googling "ansible Illegal operation attempted on a registry key that has been marked for deletion" did not yield anything useful.
While writing this question, I tried to reproduce the issue, and to get quicker results, I changed ansible_playbook.yml
from
---
- name: Jenkins node playbook
hosts: all
tasks:
- include_tasks: update_system.yml
- include_tasks: install_dependencies.yml
- include_tasks: create_user.yml
to
---
- name: Jenkins node playbook
hosts: all
tasks:
- include_tasks: create_user.yml
- include_tasks: update_system.yml
- include_tasks: install_dependencies.yml
so putting create_user.yml
first.
Result: the error could no longer be reproduced.
Then I restored to the original configuration, and I also no longer had the error.
That does not make any sense at all to me, and I don't trust it. Sounds like a Heisenbug to me.
What is this error and how can I make absolutely sure that it doesn't occur again?
@Semicolon asked in the comments for the contents of update_system.yml
and install_dependencies.yml
.
---
- name: Install all critical and security updates
win_updates:
category_names:
- CriticalUpdates
- SecurityUpdates
state: installed
register: update_result
- name: Reboot host if required
win_reboot:
when: update_result.reboot_required
---
- name: Install AWS CLI
win_shell: Import-Module AWSPowerShell
- name: install the Win32-OpenSSH service
win_chocolatey:
name: openssh
package_params: /SSHServerFeature
state: present
- name: Install required software
win_chocolatey:
name: '{{ item }}'
state: present
loop:
- openjdk11
- maven
- git
- ghostscript
- imagemagick
- nodejs
- nuget.commandline
- visualstudio2017buildtools