Ansible Remote

66 views
Skip to first unread message

Erick K

unread,
Mar 28, 2019, 8:11:30 PM3/28/19
to Packer
Thoroughly confused :(

I have Packer and Ansible installed on an Amazon Linux EC2 instance. I am able to use Packer from that instance to create an Amazon Linux image.

I am trying to configure the Ansible provisioner to install software on the image but don't have/or want to install Ansible on the image: ansible remote.

My playbook is in the same directory as my Packer JSON file. I have not configured an inventory file because I don't know what IP address the IP address of the newly created image.



- hosts: default
  gather_facts
: True
  user
: ec2-user
  sudo
: True

  tasks
:
   
- name: "update"
      yum
:
        name
: httpd
        state
: latest





{
 
"builders": [
   
{
     
"type": "amazon-ebs",
     
"access_key": "XXX",
     
"secret_key": "YYY",
     
"region": "us-east-1",
     
"source_ami": "ami-0de53d8956e8dcf80",
     
"instance_type": "t2.micro",
     
"ssh_username": "ec2-user",
     
"ami_name": "packer-example {{timestamp}}",
     
"vpc_id": "vpc-XXX",
     
"subnet_id": "subnet-XXX"
   
}
 
],
 
"provisioners": [{
   
"type": "ansible",
   
"playbook_file": "./playbook.yml",
   
"extra_arguments": "-vvvv",
   
"user": "ec2-user",
   
"host_alias": "default",
   
"extra_arguments": ["-vvvv"],
   
"ansible_env_vars": ["ANSIBLE_HOST_KEY_CHECKING=False"]
 
}]
}






Rickard von Essen

unread,
Mar 29, 2019, 2:46:44 AM3/29/19
to packe...@googlegroups.com
And what's the problem you are having? 

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/0764e808-d0d7-4d79-b8fa-44d29306b516%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Suvro Roy

unread,
Mar 29, 2019, 3:31:00 AM3/29/19
to Packer
I don't see any issue with this code. rather then you are using extra_arguments multiple times. Can you please share us more details regarding this.

Suvro Roy

unread,
Mar 29, 2019, 3:33:06 AM3/29/19
to Packer
Also please use connection: ssh in ansible playbook file.

Erick K

unread,
Mar 29, 2019, 8:49:12 AM3/29/19
to Packer
==> amazon-ebs: Provisioning with Ansible...                                                                                                                                                    
==> amazon-ebs: Executing Ansible: ansible-playbook --extra-vars packer_build_name=amazon-ebs packer_builder_type=amazon-ebs -o IdentitiesOnly=yes -i /tmp/packer-provisioner-ansible567113192 /
home/ec2-user/packer_templates/playbook.yml -e ansible_ssh_private_key_file=/tmp/ansible-key669797741                                                                                           
    amazon-ebs:                                                                                                                                                                                 
    amazon-ebs: PLAY [default] *****************************************************************                                                                                                
    amazon-ebs:                                                                                                                                                                                 
    amazon-ebs: TASK [update] ******************************************************************                                                                                                
    amazon-ebs: fatal: [default]: FAILED! => {"ansible_facts": {"pkg_mgr": "yum"}, "changed": false, "msg": "Existing lock /var/run/yum.pid: another copy is running as pid 3307.\nAnother app i
s currently holding the yum lock; waiting for it to exit...\n  The other application is: yum\n    Memory :  34 M RSS (325 MB VSZ)\n    Started: Fri Mar 29 12:37:37 2019 - 00:04 ago\n    State 
 : Sleeping, pid: 3307\nAnother app is currently holding the yum lock; waiting for it to exit...\n  The other application is: yum\n   
To unsubscribe from this group and stop receiving emails from it, send an email to packe...@googlegroups.com.

Erick K

unread,
Mar 29, 2019, 9:55:19 AM3/29/19
to Packer
What's frustrating is what could be holding a yum lock? It's not as if I am trying to do a number of installs; just one.

Rickard von Essen

unread,
Mar 29, 2019, 10:15:47 AM3/29/19
to packe...@googlegroups.com

To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/03f28479-529f-4e26-9292-f2c6a48426d2%40googlegroups.com.

Erick K

unread,
Mar 29, 2019, 12:35:55 PM3/29/19
to Packer
You're a lifesaver :-)  I'll try that

Erick K

unread,
Mar 31, 2019, 5:51:16 PM3/31/19
to Packer
My issue is now resolved. I ended up using a Ubuntu Trusty instance and began creating AMI(s) in us-east-2 (Ohio) versus us-east-1. I did not have a default VPC in us-east-1 and was unable to create one. Packer appears to work much better when you do not specify the VPC or the subnet in the Packer template. Frustrating but glad I'm now making progress. Thanks for all the help :)
Reply all
Reply to author
Forward
0 new messages