Ansible (remote) running tasks on local machine (packer build machine) instead of target image.

25 views
Skip to first unread message

Fabio Gomes Sakiyama

unread,
Oct 3, 2018, 11:44:52 AM10/3/18
to Packer
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.



Rickard von Essen

unread,
Oct 5, 2018, 3:50:44 AM10/5/18
to packe...@googlegroups.com
What do you base this claim on?

but instead, my local workspace is being affected.

I think you just get confused because Ansible connect to a local proxy that forwards the connection. From the docs:

The ansible Packer provisioner runs Ansible playbooks. It dynamically creates an Ansible inventory file configured to use SSH, runs an SSH server, executes ansible-playbook, and marshals Ansible plays through the SSH server to the machine being provisioned by Packer.


--
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/7a8d5522-d530-4c4b-ad36-e50b74df0548%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages