Search code examples
puppettheforeman

Add existing VM to TheForeman


I recently installed the foreman on a server and I want to add an existing VM as a host in foreman, but it seems that I can't achieve this through the GUI. The only option I have found is to add a NEW host, not an existing one. My VM wasn't registered with a puppet master either. Do I need to install puppet on my VM and add it manually to the puppet master that foreman includes? Is there a simpler way to do this with foreman's GUI?


Solution

  • I've only been able to accomplish this by manually configuring the host.

    On your VM

    1. First install puppet on the host ( EL Example ):

      yum install puppet -y

    2. Next you will want to configure the host's puppet.conf to point to your Foreman server as the Puppet master.

    NOTE: Replace foreman-hostname.domain.com with the FQDN of your Foreman server. NOTE: The line certname =hostname` assumes your hostname is set properly on your VM.

    Run this to create the puppet config:

    echo "Configuring puppet"
    cat > /etc/puppet/puppet.conf << EOF
    
    [main]
    vardir = /var/lib/puppet
    logdir = /var/log/puppet
    rundir = /var/run/puppet
    ssldir = \$vardir/ssl
    
    [agent]
    pluginsync      = true
    report          = true
    ignoreschedules = true
    daemon          = false
    ca_server       = foreman-hostname.domain.com
    certname        = `hostname`
    environment     = production
    server          = foreman-hostname.domain.com
    
    EOF
    
    1. Configure your server to start puppet agent on reboot ( EL Example ):

      chkconfig puppet on

    2. Check in with the puppet master you just configured and generate certs etc:

      /usr/bin/puppet agent --config /etc/puppet/puppet.conf -o --tags no_such_tag --server foreman-hostname.domain.com --no-daemonize

    On the Foreman Server

    1. Under smart proxies select certificates.
    2. The click sign by your host and your host should be added!
    3. Run puppet agent -t again, and it should check in.

    Please understand this does not give Foreman control of your VM in terms of sending delete commands to the hypervisor and stuff. This just enables control of Puppet and adding the VM to hostgroups.

    This process should be pretty easy automate too!