Hi #packer!
I am trying to learn more about Packer and Ansible. I think those too along with Terraform, Bazel and jsonnet will be great to use!
With packer I am able to pass in a playbook.yml and an inventory file to Ansible. However, I would like to be able to specify to ansible what host it is currently running on, so it knows what section of the inventory file to utilize.
I tried the `host_alias` parameter, but I then ended up with:
amazon-ebs: fatal: [master_host]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname master_host: nodename nor servname provided, or not known", "unreachable": true}
Any ideas on what is the best way to tell Ansible what machine it is provisioning through Packer?
Thank you!
Kevin
[provision.yml file:::]
---
- hosts: all
vars:
kubernetes_allow_pods_on_master: true
roles:
- geerlingguy.docker
- geerlingguy.kubernetes
[inventory_master file:::]
[master]
master_host
[master:vars]
kubernetes_role=master
[node]
node_host1
node_host2
[node:vars]
kubernetes_role=node
[example.json file:::]
{
"variables": {
"aws_access_key": "",
"aws_secret_key": ""
},
"builders": [{
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"region": "us-east-1",
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"name": "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*",
"root-device-type": "ebs"
},
"owners": ["099720109477"],
"most_recent": true
},
"instance_type": "t2.micro",
"ssh_username": "ubuntu",
"ami_name": "packer-example {{timestamp}}"
}],
"provisioners": [{
"type": "ansible",
"user": "root",
"playbook_file": "/Users/kevin/pdev/tgkj/corp/dev/provision.yml",
"inventory_file": "/Users/kevin/pdev/tgkj/corp/dev/inventory_master.yml",
"host_alias": "master_host"
}, {
"type": "shell",
"inline": [
]
}
]
}