Giter VIP home page Giter VIP logo

ansible-role-packer_rhel's Introduction

Ansible Role: Packer RHEL/CentOS Configuration for Vagrant VirtualBox

CI

This role configures RHEL/CentOS (either minimal or full install) in preparation for it to be packaged as part of a .box file for Vagrant/VirtualBox deployment using Packer.

The role may be made more flexible in the future, so it could work with other Linux flavors and/or other Packer builders besides VirtualBox, but I'm currently only focused on VirtualBox, since the main use case right now is developer VMs.

Requirements

Prior to running this role via Packer, you need to make sure Ansible is installed via a shell provisioner, and that preliminary VM configuration (like adding a vagrant user to the appropriate group and the sudoers file) is complete, generally by using a Kickstart installation file (e.g. ks.cfg) with Packer. An example array of provisioners for your Packer .json template would be something like:

"provisioners": [
  {
    "type": "shell",
    "execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'",
    "script": "scripts/ansible.sh"
  },
  {
    "type": "ansible-local",
    "playbook_file": "ansible/main.yml",
    "role_paths": [
      "/Users/jgeerling/Dropbox/VMs/roles/geerlingguy.packer_rhel",
    ]
  }
],

The files should contain, at a minimum:

scripts/ansible.sh:

#!/bin/bash -eux
# Add the EPEL repository, and install Ansible.
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum -y install ansible python-setuptools

ansible/main.yml:

---
- hosts: all
  sudo: yes
  gather_facts: yes
  roles:
    - geerlingguy.packer_rhel

You might also want to add another shell provisioner to run cleanup, erasing free space using dd, but this is not required (it will just save a little disk space in the Packer-produced .box file).

If you'd like to add additional roles, make sure you add them to the role_paths array in the template .json file, and then you can include them in main.yml as you normally would. The Ansible configuration will be run over a local connection from within the Linux environment, so all relevant files need to be copied over to the VM; configuratin for this is in the template .json file. Read more: Ansible Local Provisioner.

Role Variables

Available variables are listed below, along with default values (see defaults/main.yml):

packer_rhel_libselinux_package: libselinux-python

The libselinux python package to be installed. This is overridden for RHEL 8 to be python3-libselinux.

Dependencies

None.

Example Playbook

- hosts: all
  roles:
    - { role: geerlingguy.packer_rhel }

License

MIT / BSD

Author Information

This role was created in 2014 by Jeff Geerling, author of Ansible for DevOps.

ansible-role-packer_rhel's People

Contributors

bartjoris avatar error426 avatar geerlingguy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ansible-role-packer_rhel's Issues

VirtualBox guest additions non installed

"Run VirtualBox guest additions installation." fails silently
The issue was a mismatch between versions of just installed kernel-headers and running kernel.
The vm needed a full restart
And then I was able to install VirtualBox guest additions

How can I manage a full restart inside ansible? No way, I think
Now I'm trying to split the role:

  1. ansible pre-requisites (via "ansible-local" provisioning)
  2. restart (via packer "shell" provisioning)
  3. VirtualBox guest additions (via "ansible-local" provisioning)

Any idea? Thanks!

SSL issue

Hi

Here's my error

TASK [geerlingguy.ansible-role-packer : Download and unarchive Packer.] ***************
fatal: [brique]: FAILED! => {"changed": false, "failed": true, "msg": "Failed to validate the SSL certificate for releases.hashicorp.com:443. Make sure your managed systems have a valid CA certificate installed. You can use validate_certs=False if you do not need to confirm the servers identity but this is unsafe and not recommended. Paths checked for this platform: /etc/ssl/certs, /etc/pki/ca-trust/extracted/pem, /etc/pki/tls/certs, /usr/share/ca-certificates/cacert.org, /etc/ansible. The exception msg was: (\"bad handshake: Error([('SSL routines', 'ssl3_read_bytes', 'tlsv1 alert protocol version')],)\",)."}

Running Ubuntu 17.04 up to date. Workaround is obvious but I thought I'ld signal this, you should add validate_certs as option like ansible/ansible@a9017af

Cheers,

removing kernel-headers

Hello!

We are running into an issue where the removal of kernel-devel/headers/cpp is rendering a node unbootable after a yum upgrade. Short version - we need dkms network module rebuilt at boot when the kernel changes.

It seems here that the role is assuming it was the one to install devel/headers/cpp and should remove them now. Curious your thoughts on fixes ? Adding logic to detect -- or just a defaults var to allow role users to override the cleanup ?

Error running `packer build` in centos7 directory of geerlingguy/packer-boxes repo

Hi,

I run the above command and everything works fine until I get to this break point, which is in main.yml of this repo. Has anyone seen this before?

virtualbox-iso: TASK [geerlingguy.packer_rhel : Get Vagrant's public key.] *********************
virtualbox-iso: fatal: [127.0.0.1]: FAILED! => {"changed": false, "dest": "/home/vagrant/.ssh/authorized_keys", "elapsed": 0, "msg": "Request failed: <urlop
en error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:618)>", "url": "https://github.com/mitchellh/vagrant/raw/master/keys/vagrant.pub"}

Thanks,
Eoghan

Yum pkg command failing

I don't think yum: pkg= is supported anymore. I am receiving failures from this line. Am I confused about this? I thought this should be like this:

- name: Ensure necessary packages are installed.
  yum: name="{{ item }}" state=installed
  with_items:
    - wget
    - perl
    - cpp
    - gcc
    - make
    - bzip2
    - kernel-headers
    - kernel-devel
    - "kernel-devel-{{ kernel_release.stdout }}"
    - libselinux-python

add repo for RHEL8

I currently try to deploy a RHEL 8.x VM using your role, and it seems to fail at the missing repo.
Your template only writes the repo file when version = 7 ... I assume this is the problem here.

AFAI see here: https://www.vmware.com/support/packages.html there is no repo for RHEL 8.x, so I have to find out how to proceed here

Fix issue with VMWare builds: "Waiting for HGFS kernel module to load..."

Whenever I bring up machines using the default share (e.g. the one that is used for the /vagrant mount by default, which could be switched to NFS/rsync/SMB, or disabled, but still...), I get the following error after a while:

Waiting for HGFS kernel module to load...
The HGFS kernel module was not found on the running virtual machine.
This must be installed for shared folders to work properly. Please
install the VMware tools within the guest and try again. Note that
the VMware tools installation will succeed even if HGFS fails
to properly install. Carefully read the output of the VMware tools
installation to verify the HGFS kernel modules were installed properly.

I'd like to not have to update all my Vagrantfiles to disable the default share or switch it to NFS, so I'd like to fix this, maybe using a technique like the one here: https://bascht.com/tech/2013/10/07/building-a-vagrant-box-with-centos-64-and-vmware/

TODO

Make role work with VMware

Currently this role only works with VirtualBox (installing the guest additions). I'd like to make it so it works with VMware box builds as well (where it will install the open-vm-tools package).

Potential issues with CentOS 7.5 (1804) and Virtualbox

I recently ran into an issue with certain packer builds stalling and failing maybe 80% of the time.

This was occurring on a packer template and ansible playbook that had largely worked quite reliably for several years. I had started to update the base image to CentOS 7.5 (1804) when I first noticed it.

I originally thought it was a packer issue and wrote about it here: https://groups.google.com/forum/#!topic/packer-tool/30Uy3u-zfUo

As noted in the mailing list posts, I tried various combinations of CentOS, Virtualbox, Packer, and Ansible. None of those changes seemed to help, nor did returning to what I believed were previously known good versions and configurations.

The last system log entries observed when this issue happened were for dhcp and NetworkManager.

What has appeared to help though is removing several tasks from this role:

  • Fix slow DNS (adapted from Bento).
  • Restart network service (explicitly).
  • Remove RedHat interface persistence (step 1).
  • Remove RedHat interface persistence (step 2).

These changes appear to result in stable runs with Vagrant 2.1.1, Virtualbox 5.2.12 on OSX, Packer 1.2.3, and Ansible 2.5.3.

Unfortunately, I don't have a repeatable test case that I can share right now. The playbook I'm using is building an "everything" development environment and runs for some time. I have a theory that a shorter run would possibly not run long enough for the dhcp retries and timeouts noted in the mailing list post to show up.

I would be interested to hear if others have any similar issues with this configuration and whether removing these tasks helps the issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.