Ansible - Provision AWS - Unreachable

35 views
Skip to first unread message

Jeff Baldwin

unread,
Aug 29, 2019, 8:00:05 AM8/29/19
to Packer
All,

I have the JSON packer file below.   Goal is to provision an AWS AMI by leveraging Ansible.   However, Ansible is unable to connect to run the playbooks.   Curious if there are suggestions for steps/tests I can perform to troubleshoot?

=========================
JSON
=========================

[root@packer-prod packer-linbase]# cat rhel7_baseline.json
{
"variables": {
    "aws_access_key": "",
    "aws_secret_key": "",
    "vpc_id": "vpc-020799f44ba374784",
    "subnet_id": "subnet-0f95c019509596983",
    "ami_name" : "JCB_RHEL7.5-{{isotime \"2006.01.02\"}}"
  },
  "builders": [
    {
      "type": "amazon-ebs",
      "source_ami_filter": {
      "filters": {
      "virtualization-type": "hvm",
      "name": "RHEL-7.5_HVM_GA-*",
      "root-device-type": "ebs"
    },
    "owners": ["309956199498"],
    "most_recent": true
  },
"ami_users": ["523964800262"],
"ami_regions" : ["us-west-2"],
      "security_group_id": "sg-087e7ccd56066c1d9",
      "instance_type": "t2.large",
      "access_key": "{{user `aws_access_key`}}",
      "communicator": "ssh",
      "ssh_username": "ec2-user",
      "force_deregister": "true",
      "force_delete_snapshot": "true",
      "secret_key": "{{user `aws_secret_key`}}",
      "region": "us-east-1",
      "vpc_id": "{{user `vpc_id`}}",
      "launch_block_device_mappings": [
                {
                    "device_name": "/dev/sda1",
                    "delete_on_termination": true,
                    "volume_size": 100,
                    "volume_type": "gp2"
                }
            ],
    "subnet_id": "{{user `subnet_id`}}",
      "ami_name": "{{user `ami_name`}}",
      "encrypt_boot": false,
      "tags": {
        "Timestamp": "{{user `timestamp`}}"
      }
    }
  ],
  "provisioners": [{
     "type": "ansible",
     "playbook_file": "/scripts/aws-packer/packer-linbase/osbaseline.yml"
  }]
}

======================
DEBUG LOG OUTPUT
======================

[root@packer-prod packer-linbase]# /var/lib/jenkins/.local/bin/packer build -debug /scripts/aws-packer/packer-linbase/rhel7_baseline.json
Debug mode enabled. Builds will not be parallelized.
amazon-ebs output will be in this color.

==> amazon-ebs: Force Deregister flag found, skipping prevalidating AMI Name
==> amazon-ebs: Pausing after run of step 'StepPreValidate'. Press enter to continue.
    amazon-ebs: Found Image ID: ami-6871a115
==> amazon-ebs: Pausing after run of step 'StepSourceAMIInfo'. Press enter to continue.
==> amazon-ebs: Creating temporary keypair: packer_5d67bc77-e918-7b4a-f301-98b461b979a2
    amazon-ebs: Saving key for debug purposes: ec2_amazon-ebs.pem
==> amazon-ebs: Pausing after run of step 'StepKeyPair'. Press enter to continue.
==> amazon-ebs: Pausing after run of step 'StepSecurityGroup'. Press enter to continue.
==> amazon-ebs: Pausing after run of step 'StepCleanupVolumes'. Press enter to continue.
==> amazon-ebs: Launching a source AWS instance...
==> amazon-ebs: Adding tags to source instance
    amazon-ebs: Adding tag: "Name": "Packer Builder"
    amazon-ebs: Instance ID: i-022d0f6cbc22c5acc
==> amazon-ebs: Waiting for instance (i-022d0f6cbc22c5acc) to become ready...
    amazon-ebs: Private IP: 10.160.20.200
==> amazon-ebs: Pausing after run of step 'StepRunSourceInstance'. Press enter to continue.
==> amazon-ebs: Pausing after run of step 'StepGetPassword'. Press enter to continue.
==> amazon-ebs: Using ssh communicator to connect: 10.160.20.200
==> amazon-ebs: Waiting for SSH to become available...
==> amazon-ebs: Connected to SSH!
==> amazon-ebs: Pausing after run of step 'StepConnect'. Press enter to continue.
==> amazon-ebs: Pausing before the next provisioner . Press enter to continue.
==> amazon-ebs: Provisioning with Ansible...
==> amazon-ebs: Executing Ansible: ansible-playbook --extra-vars packer_build_name=amazon-ebs packer_builder_type=amazon-ebs -i /tmp/packer-provisioner-ansible374609121 /scripts/aws-packer/packer-linbase/osbaseline.yml -e ansible_ssh_private_key_file=/tmp/ansible-key960483082
    amazon-ebs:
    amazon-ebs: PLAY [BaseLine RHEL Image] *****************************************************
    amazon-ebs:
    amazon-ebs: TASK [Gathering Facts] *********************************************************
    amazon-ebs: fatal: [default]: UNREACHABLE! => {"changed": false, "msg": "Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in \"/tmp\". Failed command was: ( umask 77 && mkdir -p \"` echo /root/.ansible/tmp/ansible-tmp-1567079685.07-87262081719462 `\" && echo ansible-tmp-1567079685.07-87262081719462=\"` echo /root/.ansible/tmp/ansible-tmp-1567079685.07-87262081719462 `\" ), exited with result 1", "unreachable": true}
    amazon-ebs:         to retry, use: --limit @/scripts/aws-packer/packer-linbase/osbaseline.retry
    amazon-ebs:
    amazon-ebs: PLAY RECAP *********************************************************************
    amazon-ebs: default                    : ok=0    changed=0    unreachable=1    failed=0
    amazon-ebs:
==> amazon-ebs: Pausing before cleanup of step 'StepConnect'. Press enter to continue.
==> amazon-ebs: Pausing before cleanup of step 'StepGetPassword'. Press enter to continue.
==> amazon-ebs: Pausing before cleanup of step 'StepRunSourceInstance'. Press enter to continue.
==> amazon-ebs: Terminating the source AWS instance...
==> amazon-ebs: Pausing before cleanup of step 'StepCleanupVolumes'. Press enter to continue.
==> amazon-ebs: Cleaning up any extra volumes...
==> amazon-ebs: No volumes to clean up, skipping
==> amazon-ebs: Pausing before cleanup of step 'StepSecurityGroup'. Press enter to continue.
==> amazon-ebs: Pausing before cleanup of step 'StepKeyPair'. Press enter to continue.
==> amazon-ebs: Deleting temporary keypair...
==> amazon-ebs: Pausing before cleanup of step 'StepSourceAMIInfo'. Press enter to continue.
==> amazon-ebs: Pausing before cleanup of step 'StepPreValidate'. Press enter to continue.
Build 'amazon-ebs' errored: Error executing Ansible: Non-zero exit status: exit status 4

==> Some builds didn't complete successfully and had errors:
--> amazon-ebs: Error executing Ansible: Non-zero exit status: exit status 4

==> Builds finished but no artifacts were created.

Jeff Baldwin

unread,
Aug 30, 2019, 8:24:25 AM8/30/19
to Packer
This was in issue on my side.   Environmental variables were missing with the user I was working as.   Carry on!  :)
Reply all
Reply to author
Forward
0 new messages