I want to create an AWS instance using Terraform and run a Puppet module inside it. I have tried many modules from github and nothing seems to work. Has anyone tried this?
The way you basically have to do this is install puppet locally with a remote-exec provisioner and then either do an apply or agent execution. First, setup your instance resource like this:
resource "aws_instance" "instance_name" {
...
provisioner "remote-exec" {
script = "puppet.sh"
}
}
Swap out aws_instance for a different cloud provider if/when not using AWS (Azure, DO, GCE, etc.) Then, use the script to install Puppet, execute apply or the agent, and then uninstall Puppet (if you are not activelly managing the instance afterward, which you likely would not be in the cloud).
#!/bin/sh
# debian family example; swap out 'apt' and package names where necessary
# prep puppet
sudo apt-get update && sudo apt-get install ruby -y
sudo gem install --no-document puppet
# apply puppet
sudo puppet apply manifest.pp
# remove puppet
sudo gem uninstall -aIx
sudo apt-get remove ruby -y
sudo apt-get autoremove -y
There are some variations on this. For example, you can curl against your Puppet Master or subscribe to the Puppetlabs package repository to install Puppet AIO. You can also do puppet agent -t afterward instead of a puppet apply. This may be preferable as transferring your modules over to be used with apply can be onerous.
For a similar use case but using ansible instead of puppet, we use null_resource along with local-exec.
resource "null_resource" "lvm_housekeeping" {
triggers {
ebs_volume_ids = "${join(",", aws_volume_attachment.instance_ebs_attachment.*.volume_id)}"
}
provisioner "local-exec" {
command = "ANSIBLE_CONFIG=$HOME/'${var.ansible_repo_location}'/ansible.cfg ansible-playbook -u ec2-user -e target=all -i '${join(",",aws_instance.my_instance.*.private_ip)}, ' $HOME/'${var.ansible_repo_location}'/main.yml"
on_failure = "continue"
}
}
Related
I'm following a blog to Deploy a Debian Linux VM Instance in GCP using Terraform, in which it uses metadata_startup_script Bootstrapping Script to Install/config packages.
I'm following in Azure instead of GCP, and got:
An argument named "metadata_startup_script" is not expected here.
Is metadata_startup_script GCP provider speicific? What's the corresponding mechanism in the terraform Azure provider ? For e.g. to do the following,
sudo apt-get update;
sudo apt-get install -y apache2;
sudo systemctl start apache2;
sudo systemctl enable apache2;
to bootstrap the provided Linux VM?
The attribute metadata_startup_script doesn't exist on Azure VMs, its similar is user_data[1].
References:
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine#user_data
Puppet Version: 3.8.7
I have been working on building some system monitoring boxes and have ran into an issue when it comes to installing group yum packages. The normal course of installing packages of course isn't working but I figured that I would at least be able to work around this by including an exec to run the install as a command (like below):
exec { "GNOME Desktop":
command => "/usr/bin/yum -y groups install 'GNOME Desktop'",
timeout => 600,
}
There is an available module on the puppet forge that seems to do what I want but it's not compatible with our version of puppet and we are not in a place to upgrade at this time.
I also tried the setup that was listed in the below server fault question but it also did not work for me:
https://serverfault.com/questions/127460/how-do-i-install-a-yum-package-group-with-puppet
I have also manually been able to run the following command but when I exec it as a puppet command, it fails:
/usr/bin/yum -y groups install "GNOME Desktop"
Why is this? I assumed that puppet is just issuing the command in the exact same way the terminal would?
Changing the time out (or removing it) had zero effect, the issue is with the version of puppet and the ability to install group packages. I ended up installing the desktop environment in my kickstart file and ran puppet for everything else.
I'm currently having trouble getting my module to work.
My goal here is to have a script that will add a repository to install brackets, install puppet, and copy an existing module
finaldigi/manifests/init.pp ---->>> /etc/puppet/modules folder
For some reason, the module works if I do all the script commands manually, but when I put them in a script and run it, it shows this error:
Error: Puppet::Parser::AST::Resource failed with error ArgumentError:
Could not find declared class packagemodule at line 1 on node
xubuntu.dhcp.inet.fi
Error: Puppet::Parser::AST::Resource failed with error ArgumentError:
Could not find declared class packagemodule at line 1 on node
xubuntu.dhcp.inet.fi
Here is my init.pp file
class packagemodule {
package { brackets:
ensure => 'installed',
allowcdrom => 'true',
}
package { apache2:
ensure => 'installed',
allowcdrom => 'true',
}
file {'/var/www/html/index.html':
content => "testing testing",
}
}
And my script:
#!/bin/bash
echo | sudo add-apt-repository ppa:webupd8team/brackets
sudo apt-get update
sudo apt-get install -y puppet
sudo cp -r ./finaldigi /etc/puppet/modules
sudo puppet apply -e 'class {packagemodule:}'
So yeah, it DOES work and won't show any errors if I type all the commands MANUALLY, but if I start putting all those commands in my bash script, it doesn't work and starts showing that error.
What am I missing here?
sudo cp -r ./finaldigi /etc/puppet/modules
This will create /etc/puppet/modules/finaldigi and /etc/puppet/modules/finaldigi/manifests/init.pp, but the directory should be called packagemodule if that's the class name you're using inside.
Change this to:
sudo cp -r ./finaldigi /etc/puppet/modules/packagemodule
(If this doesn't work, please provide a find /etc/puppet/modules output, provide the Puppet version you're using, and output of puppet apply --configprint modulepath)
puppet master was working fine in my ubuntu 12.04 server. Today I uninstalled it using the following commands and made a fresh install again. After a fresh install, puppet master failed to start.
sudo apt-get remove puppetmaster-common
sudo apt-get remove --auto-remove puppetmaster-common
sudo apt-get purge puppetmaster-common
sudo apt-get purge --auto-remove puppetmaster-common
sudo apt-get remove puppet
sudo apt-get remove --auto-remove puppet
sudo apt-get purge puppet
sudo apt-get purge --auto-remove puppet
After a fresh install, it's totally stopped working and I am getting the below errors in log
Could not autoload puppet/type/user: Could not autoload
puppet/provider/user/directoryservice: cannot load such file
Could not autoload puppet/provider/user/directoryservice: cannot load
such file -- plist
Could not autoload puppet/type/user: Could not autoload
puppet/provider/user/directoryservice: cannot load such file
Could not create resources for managing Puppet's files and directories
in sections [:main, :master, :ssl, :metrics]
Could not prepare for execution: Could not create resources for
managing Puppet's files and directories in sections
Also, there is no puppet.conf file exists in /etc/puppet/puppet.conf location even after fresh install. I tried installing twice and I couldn't see this file getting generated.
Puppet version 3.8.5.
Ubuntu : 12.04 version
Could someone help me to resolve this issue?
Matt, I figured it out finally.
I just removed the existing apt repository by manually deleting the entries in
/etc/apt/sources.list.d
and removed puppetlabls-pc1.list, puppet.list, puppet.save, all entries related to puppet and then invoked
sudo apt-get update
And installed puppet master once again without appending any additional apt repos
sudo apt-get -y install puppetmaster
I think I was using wrong apt source. It wasn't generating puppet.conf file at all. May be thats the reason why I was getting weired errors like that
I use vagrant 1.0.1 on a precise32 base box to play with puppet.
Provisioning works fine, my manifests are being executed.
By default vagrant installs puppet 2.7.14 under /opt/vagrant_ruby/bin/puppet on the guest.
How can I configure vagrant (or who ever installs puppet on the guest) to use a more recent version like puppet 3.0 or 3.1?
Also you could update puppet with shell provisioner specified before puppet provisioner. As said in Vagrant documentation:
Multiple config.vm.provision methods can be used to define multiple provisioners. These provisioners will be run in the order they're defined. This is useful for a variety of reasons, but most commonly it is used so that a shell script can bootstrap some of the system so that another provisioner can take over later.
Here is example Vagrantfile for CentOS 6:
# Update puppet to version 3.2.2 before using puppet provisioning.
$puppet_update_script = <<SCRIPT
[ `rpm -qa puppetlabs-release` = 'puppetlabs-release-6-7.noarch' ] || rpm -ivh http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-7.noarch.rpm
[ `rpm -qa puppet` = 'puppet-3.2.2-1.el6.noarch' ] || yum -y update-to puppet-3.2.2
SCRIPT
config.vm.provision :shell, :inline => $puppet_update_script
# Puppet-3.2.2 provisioning here
config.vm.provision :puppet do |puppet|
puppet.options = '--parser future'
puppet.manifests_path = 'puppet/manifests'
end
You need to rebuild the basebox that you are using in vagrant and install whatever version of Puppet you want. I did the same for Cent 6.3 w/puppet 3.0. The Veewee gem is a great utility to building and managing Vagrant baseboxes for Oracle Virtualbox.