{"id":572,"date":"2014-10-07T22:23:56","date_gmt":"2014-10-08T04:23:56","guid":{"rendered":"http:\/\/www.crccheck.com\/blog\/?p=572"},"modified":"2015-10-11T22:22:09","modified_gmt":"2015-10-12T04:22:09","slug":"testing-ansibile-playbooks-with-vagrant","status":"publish","type":"post","link":"https:\/\/www.crccheck.com\/blog\/testing-ansibile-playbooks-with-vagrant\/","title":{"rendered":"Testing Ansibile Playbooks with Vagrant"},"content":{"rendered":"<p>I&#8217;ve been interested in Ansible for a long time now, and thanks to my coworker&#8217;s expertise, I&#8217;ve been able to get my feet wet. My main barrier has been finding a way to run playbooks.<\/p>\n<ul>\n<li>For my first attempt at learning Ansible, I tried running it locally using `ansible_connection=local`. But I found that running it on a system where changes persisted made it hard to trace what was going on. The final straw was trying to locate guides and resources about how to use Ansible was so difficult. You need documentation for how to read the documentation.<\/li>\n<li>For my second attempt at learning Ansible, I tried running Vagrant in Ubuntu 14.04, but for some reason, it would not even install.<\/li>\n<li>For my third attempt at learning Ansible, I tried running it against a Docker container, but the lack of ssh and pid 1 made re-creating the full experience too difficult. I found that I could get 80% of the way there using tricks from http:\/\/phusion.github.io\/baseimage-docker\/ and https:\/\/docs.docker.com\/examples\/running_ssh_service\/<\/li>\n<li>For my fourth attempt at learning Ansible, I tried getting Vagrant up and running on my Windows machine, and it worked! It also started working on my Ubuntu machine too.<\/li>\n<\/ul>\n<p>Then I started following reading: <a href=\"http:\/\/docs.ansible.com\/guide_vagrant.html\">docs.ansible.com\/guide_vagrant.html<\/a>, but modified it for my own purposes. I got this working in Windows first, but everything here works exactly the same in Linux and OSX too.<\/p>\n<p>I made a few minor modifications I&#8217;ll go over now. I changed the base box to be similar to what we use in production and to one that wasn&#8217;t two years old. In my case, trusty64:<\/p>\n<pre>$ vagrant init ubuntu\/trusty64<\/pre>\n<p>Then, I adjusted the Vagrantfile to use a shell provisioner. Here&#8217;s a mine (with comments removed):<\/p>\n<pre>VAGRANTFILE_API_VERSION = \"2\"<\/pre>\n<pre>Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|\r\n  config.vm.box = \"ubuntu\/trusty64\"\r\n  config.hostname = \"ansible-test\"\r\n  config.vm.box_check_update = false\r\n  config.vm.network \"public_network\"\r\n  config.vm.provision :shell, :privileged =&gt; false, :path =&gt; 'vagrant-install.sh'\r\nend<\/pre>\n<p>And this is contents of vagrant-install.sh referenced above:<\/p>\n<pre>echo `whoami`\r\nsudo apt-get update -qq\r\nsudo apt-get install -y avahi-daemon<\/pre>\n<p>Using avahi\/zeroconf gives me a hostname on my local network so I can use a predictable and human friendly hostname.<\/p>\n<p>Let&#8217;s get started!<\/p>\n<pre>$ vagrant up<\/pre>\n<p>And now let&#8217;s run our playbook, jenkins.yml<\/p>\n<pre>$ ansible-playbook --private-key=~\/.vagrant.d\/insecure_private_key -u vagrant jenkins.yml<\/pre>\n<p>To get it to connect to ansible-test.local, I hacked my\u00c2\u00a0 <code>\/etc\/ansible\/hosts<\/code> file according to these instructions: <a href=\"http:\/\/docs.ansible.com\/intro_inventory.html#hosts-and-groups\">docs.ansible.com\/intro_inventory.html#hosts-and-groups<\/a><\/p>\n<p>So how do I feel about Ansible? It&#8217;s meh. I still hate it, but I hate it less than Chef and Puppet. I hate them all so much.<\/p>\n<p><a href=\"http:\/\/www.crccheck.com\/blog\/wp-content\/uploads\/2014\/10\/7s2dfdt.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-581\" src=\"http:\/\/www.crccheck.com\/blog\/wp-content\/uploads\/2014\/10\/7s2dfdt-300x194.jpg\" alt=\"Let the hate flow through you\" width=\"300\" height=\"194\" srcset=\"https:\/\/www.crccheck.com\/blog\/wp-content\/uploads\/2014\/10\/7s2dfdt-300x194.jpg 300w, https:\/\/www.crccheck.com\/blog\/wp-content\/uploads\/2014\/10\/7s2dfdt.jpg 900w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been interested in Ansible for a long time now, and thanks to my coworker&#8217;s expertise, I&#8217;ve been able to get my feet wet. My main barrier has been finding a way to run playbooks. For my first attempt at learning Ansible, I tried running it locally using `ansible_connection=local`. But I found that running it&hellip;<\/p>\n <a href=\"https:\/\/www.crccheck.com\/blog\/testing-ansibile-playbooks-with-vagrant\/\" title=\"Testing Ansibile Playbooks with Vagrant\" class=\"entry-more-link\"><span>Read More<\/span> <span class=\"screen-reader-text\">Testing Ansibile Playbooks with Vagrant<\/span><\/a>","protected":false},"author":2,"featured_media":581,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[4],"tags":[72,34,71],"class_list":["entry","author-showmewhatyougot","post-572","post","type-post","status-publish","format-standard","has-post-thumbnail","category-technical","tag-ansible","tag-linux","tag-vagrant"],"_links":{"self":[{"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/posts\/572","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/comments?post=572"}],"version-history":[{"count":11,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/posts\/572\/revisions"}],"predecessor-version":[{"id":604,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/posts\/572\/revisions\/604"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/media\/581"}],"wp:attachment":[{"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/media?parent=572"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/categories?post=572"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/tags?post=572"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}