Justin Flammia
Justin Flammia

Reputation: 233

Seemingly Random Timeouts using Packer with Ansible on AWS

I am baking AWS AMIs using Packer and Ansible. It seems that after about 6 minutes or so of Packer running, the process will fail. Aside from it taking about 6 minutes, I can't seem to find a logical explanation as to what is happening. The Ansbile playbook will fail at different points along the way but always about 6 minutes after I launch Packer.

I always get an Ansible error when I hit this issue. I either get Timeout (12s) waiting for privilege escalation prompt: or Connection to 127.0.0.1 closed.\r\n

Is there a way to extend the timeouts associated with a playbook or Packer builder?

Packer file contents:

{
  "provisioners": [{
    "type": "ansible",
    "playbook_file": "../ansible/nexus.yml"
  }],

  "builders": [{
    "type": "amazon-ebs",
    "region": "us-east-2",
    "source_ami_filter": {
        "filters": {
            "virtualization-type": "hvm",
            "name": "amzn-ami-hvm*-gp2",
            "root-device-type": "ebs"
        },
        "owners": ["137112412989"],
        "most_recent": true
    },
    "instance_type": "t2.medium",
    "ami_virtualization_type": "hvm",
    "ssh_username": "ec2-user",
    "ami_name": "Nexus (Latest Amazon Linux Base) {{isotime \"2006-01-02T15-04-05-06Z\"| clean_ami_name}}",
    "ami_description": "Nexus AMI",
    "run_tags": {
        "AmiName": "Nexus",
        "AmiCreatedBy": "Packer"
    },
    "tags": {
        "Name": "Nexus",
        "CreatedBy": "Packer"
    }
  }]
}

Upvotes: 0

Views: 913

Answers (1)

viniciusfs
viniciusfs

Reputation: 181

I solved this issue adding following parameters at Ansible configuration file:

[defaults]
forks = 1

[ssh_connection]
ssh_args = -o ControlMaster=no -o ControlPath=none -o ControlPersist=no
pipelining = false

Hope it helps.

Upvotes: 1

Related Questions