Hi,
I read about ansible-local and ansible, I'm still confused but what I understood was:
ansible-local - Runs on target machine which is being built by packer image, so it needs ansible installed.
ansible (remote) - Runs on local machine (where I run packer build) targetting the machine which is being built by packer image. Doesn't required ansible on target machine.
The second option (remote) seems like the way I'm already working, running playbooks on my local workspace targetting machines through ansible hosts.
I'm struggling to understand what I'm doing wrong with packer. I have a packer.json to configure the resolv.conf for example:
{
"variables": {
"service_account_json": "../shared/account.json",
"repo_path" : "{{env `REPO_PATH`}}",
"project_id": "{{env `PROJECT_ID`}}"
},
"builders": [
{
"type": "googlecompute",
"project_id": "{{user `project_id`}}",
"machine_type": "n1-standard-1",
"source_image": "centos-7-v20180911",
"region": "us-east1",
"zone": "us-east1-b",
"image_description": "Image based on CentOS7 image to have the resolv.conf configured, the yum repo configured and yum.conf configured",
"image_name": "devopsdefault2",
"disk_size": 10,
"ssh_username": "fabiosakiyama",
"account_file": "{{ user `service_account_json`}}"
}
],
"provisioners": [
{
"type": "ansible",
"extra_arguments": [ "-vvvv" ],
"ansible_env_vars": [
"ANSIBLE_ROLES_PATH=../ansible/roles/:$ANSIBLE_ROLES_PATH"
],
"playbook_file": "../ansible/playbooks/configure-centos-base-image.yml"
}
]
}It calls a playbook:
---
- hosts: localhost
become: yes
roles:
- centos-base-conf
that calls a role:
---
# tasks file for centos-base-conf
- name: calls configure-resolv-conf
import_tasks: configure-resolv-conf.yaml
- name: calls configure-yum-repo
import_tasks: configure-yum-repo.yaml
- name: calls configure-yum-conf
import_tasks: configure-yum-conf.yaml
and one of the tasks is to config the resolv.conf:
- name: replace resolv.conf
copy:
src: resolv.conf
dest: /etc/resolv.conf
owner: root
group: root
mode: u=rw,g=r,o=r
(the resolv.conf is inside the role file folder).
I expect that the image will be created with my customized resolv.conf, but instead, my local workspace is being affected.
What I'm missing here?
Thanks in advance.