Running Ansible on Windows using Packer on AWS

I am trying to provide an Ansible playbook using a wrapper on Windows AMI.
This is my packer template:

{
  "variables": {
    "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}",
    "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}",
    "aws_region": "{{env `AWS_DEFAULT_REGION`}}",
    "aws_source_ami": "*****",
    "ssh_username": "{{env `AWS_AMI_USERNAME`}}",
    "aws_instance_type": "m1.medium",
    "name": "windows2012-...",
    "packer_dir": "/opt/packer",
    "home": "{{env `HOME`}}"
},
  "builders": [{
    "type": "amazon-ebs",
    "access_key": "{{user `aws_access_key`}}",
    "secret_key": "{{user `aws_secret_key`}}",
    "region": "{{user `aws_region`}}",
    "source_ami": "{{user `aws_source_ami`}}",
    "ami_regions": ["{{user `aws_region`}}"],
    "instance_type": "{{user `aws_instance_type`}}",
    "communicator": "winrm",
    "winrm_username": "Administrator",
    "winrm_use_ssl": true,
    "winrm_insecure": true,
    "winrm_timeout": "12h",
    "user_data_file": "scripts/userdata_setup.ps1",
    "ami_name": "{{user `name`}}-ami",
    "ami_description": "{{user `name`}}-ami",
    "associate_public_ip_address": true,
    "launch_block_device_mappings": [{
      "device_name": "/dev/xvda",
      "volume_type": "gp2",
      "volume_size": 50,
      "delete_on_termination": true
  }],
    "tags": {
      "artifact": "{{user `name`}}"
    }
  }],
  "provisioners": [
    {
      "type": "powershell",
      "script": "scripts/ConfigureRemotingForAnsible.ps1"
    },
    {
      "type": "ansible",
      "playbook_file": "/path/to/playbook_file.yml",
      "extra_arguments" : [
        "--extra-vars", "ansible_user=Administrator ansible_connection=winrm ansible_winrm_server_cert_validation=ignore"
      ]
    }
  ]
}

      

When I run packer build my_template.json


I get the following error while Ansible Proviser is running:

amazon-ebs: TASK [Gathering Facts] *********************************************************
amazon-ebs: fatal: [default]: UNREACHABLE! => {"changed": false, "msg":
            "ssl: HTTPSConnectionPool(host='127.0.0.1', port=5986): Max retries
            exceeded with url: /wsman (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x102ba6f90>: 
            Failed to establish a new connection: [Errno 61] Connection refused',))", "unreachable": true}

      

I am assuming I am doing something wrong (why is host 127.0.0.1?), But I haven't found any documentation on how to run ansible with a packager on Windows in an AMI.

Does anyone know what I am doing wrong? How can I solve the problem?


Regards,
Adam

+3


source to share


1 answer


You need to follow the instructions in the Packer Documentation - Ansible: winrm communicator and use a custom connection plugin and use the following ansible

Proviser args:



  "extra_arguments": [
    "--connection", "packer",
    "--extra-vars", "ansible_shell_type=powershell ansible_shell_executable=None"
  ]

      

0


source







All Articles