2

I am trying to setup my development environment (on my local Linux pc) via some automatic mechanism. I tried ansible playbooks, they work quite well.

Let's assume a playbook like this ("SetupDevEnv.yml")

---
- hosts: localhost
  tasks:
    - name: install packages
      apt:
        state: present
        name:
         - gcc
         - clang
         - vscode
         - ...

After running :

$ ansible-playbook SetupDevEnv.yml

My local pc is ready to go with all the toolchain tools needed (gcc, clang, vscode, ...).

Is it possible to do the same thing with packer? If yes, how would it look like? Would it also be possible to use the existing Ansible playbooks?

Remark1: The important point here is I want to do it for my local pc (localhost) only. I do not want to generate a VM or a Docker container to which I have to log in afterward. The idea is: the "SetupDevEnv.yml" (or the packer file) is located in the repository. The developer checks out the repository runs the setup generation and starts to work.

Remark2: To clarify the question, my question is: "How would the packer HCL/json file look like to do the same as in "SetupDevEnv.yml"? Or how would the packer HCL/json file look like which uses the "SetupDevEnv.yml"? If this is possible.

user1911091
  • 1,219
  • 2
  • 14
  • 32

1 Answers1

3

Sure. Supposing you're installing Packer using the APT repositories provided by Hashicorp on Ubuntu 20.04, that could be accomplished with the following playbook:

--- 
- hosts: localhost
  connection: local
  become: true
  tasks:
    - name: Add Hashicorp's GPG key
      apt_key:
        state: present
        url: https://apt.releases.hashicorp.com/gpg

    - name: Add Hashicorp's repository
      apt_repository:
        mode: 0644
        repo: deb [arch=amd64] https://apt.releases.hashicorp.com focal main
        state: present
        update_cache: yes
      
    - name: Install Packer
      apt:
        name: packer
        state: present

Best regards!

Stefano Martins
  • 472
  • 2
  • 7
  • Thank you. But this is just a ansible playbook to install packer, or? Or can one use your *.yml file above in packer? How would the packer HCL/json file look like to do the same as in "SetupDevEnv.yml"? Or how to include the "SetupDevEnv.yml" into the packer file? – user1911091 Apr 20 '21 at 07:32
  • This is a full playbook. To append it to your `SetupDevEnv.yml`, you could just copy/paste the modules part into it. =) – Stefano Martins Apr 20 '21 at 13:16