{"id":26227,"date":"2016-07-07T09:25:10","date_gmt":"2016-07-07T07:25:10","guid":{"rendered":"https:\/\/mamchenkov.net\/wordpress\/?p=26227"},"modified":"2019-02-25T12:05:16","modified_gmt":"2019-02-25T10:05:16","slug":"forcing-amazon-linux-ami-compatibility-with-centos-in-ansible","status":"publish","type":"post","link":"https:\/\/mamchenkov.net\/wordpress\/2016\/07\/07\/forcing-amazon-linux-ami-compatibility-with-centos-in-ansible\/","title":{"rendered":"Forcing Amazon Linux AMI compatibility with CentOS in Ansible"},"content":{"rendered":"<!-- google_ad_section_start -->\n<p>One of the things that makes Ansible so awesome is a huge collection of shared roles over at <a href=\"https:\/\/galaxy.ansible.com\">Ansible Galaxy<\/a>. &nbsp;These bring you best practices, flexible configurations and in general save hours and hours of hardcore swearing and hair pulling.<\/p>\n<p>Each role usually supports multiple versions of multiple Linux distributions. &nbsp;However, you&#8217;ll find that the majority of the supported distributions are Ubuntu, Debian, Red Hat Enterprise Linux, CentOS, and Fedora. &nbsp;The rest aren&#8217;t as popular.<\/p>\n<p>Which brings me to the point with <a href=\"https:\/\/aws.amazon.com\/amazon-linux-ami\/\">Amazon Linux AMI<\/a>. &nbsp;Amazon Linux AMI is mostly compatible with CentOS, but it uses a different version approach, which means that most of those Ansible roles will ignore or complain about not supporting Amazon AMI.<\/p>\n<p>Here is an example I came across yesterday from the&nbsp;<a href=\"https:\/\/galaxy.ansible.com\/dj-wasabi\/zabbix-server\/\">dj-wasabi.zabbix-server<\/a> role. &nbsp;The <a href=\"https:\/\/github.com\/dj-wasabi\/ansible-zabbix-server\/blob\/master\/templates\/rhel.repo.j2\">template for the Yum repository<\/a> uses <strong>ansible_os_major_version<\/strong> variable, which is expected to be similar to Red Hat \/ CentOS version number &#8211; 5, 6, 7, etc. &nbsp;Amazon Linux AMI&#8217;s major version is reported as &#8220;NA&#8221; &#8211; not available. &nbsp; That&#8217;s probably because Amazon Linux AMI versions are date-based &#8211; with the latest one being <a href=\"https:\/\/aws.amazon.com\/amazon-linux-ami\/2016.03-release-notes\/\">2016.03<\/a>.<\/p>\n<pre class=\"brush: plain; light: true; title: ; notranslate\" title=\"\">\n&#x5B;zabbix]\nname=Zabbix Official Repository - $basearch\nbaseurl=http:\/\/repo.zabbix.com\/zabbix\/{{ zabbix_version }}\/rhel\/{{ ansible_distribution_major_version }}\/$basearch\/\nenabled=1\ngpgcheck=0\ngpgkey=file:\/\/\/etc\/pki\/rpm-gpg\/RPM-GPG-KEY-ZABBIX\n<\/pre>\n<p>Officially, Amazon Linux AMI is not CentOS or Red Hat Enterprise Linux. &nbsp;But if you don&#8217;t care about such little nuances, and you are brave enough to experiment and assume things, than you can make that role work, by simply setting the appropriate variables to the values that you want.<\/p>\n<p>First, here is a standalone <em>test.yml<\/em> playbook to try things out:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n- name: Test\nhosts: localhost\npre_tasks:\n- set_fact: ansible_distribution_major_version=6\nwhen: ansible_distribution == &quot;Amazon&quot;\ntasks:\n- debug: msg={{ ansible_distribution_major_version }}\n<\/pre>\n<p>Let&#8217;s run it and look at the output:<\/p>\n<pre class=\"brush: plain; light: true; title: ; notranslate\" title=\"\">\n$ ansible-playbook test.yml\n\nPLAY &#x5B;Test] *******************************************************************\n\nGATHERING FACTS ***************************************************************\nok: &#x5B;localhost]\n\nTASK: &#x5B;set_fact ansible_distribution_major_version=6] *************************\nok: &#x5B;localhost]\n\nTASK: &#x5B;debug msg={{ ansible_distribution_major_version }}] ********************\nok: &#x5B;localhost] =&amp;gt; {\n&quot;msg&quot;: &quot;6&quot;\n}\n\nPLAY RECAP ********************************************************************\nlocalhost : ok=3 changed=0 unreachable=0 failed=0\n<\/pre>\n<p>So far so good. &nbsp;Now we need to integrate this into our playbook in such a way that the variable is set before the third-party role is executed. &nbsp;For that, we&#8217;ll use <a href=\"http:\/\/docs.ansible.com\/ansible\/playbooks_roles.html#roles\">pre_tasks<\/a>. &nbsp;Here is an example:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n---\n- name: Zabbix Server\nhosts: zabbix.server\nsudo: yes\npre_tasks:\n- set_fact: ansible_distribution_major_version=6\nwhen: ansible_distribution == &quot;Amazon&quot; and ansible_distribution_major_version == &quot;NA&quot;\nroles:\n- role: dj-wasabi.zabbix-server\n<\/pre>\n<p>A minor twist here is also checking if the major version is not set yet. You can skip that, or you can change it, for example, to examine the Amazon Linux AMI version and set corresponding CentOS version.<\/p>\n<!-- google_ad_section_end -->\n","protected":false},"excerpt":{"rendered":"<!-- google_ad_section_start -->\n<p>One of the things that makes Ansible so awesome is a huge collection of shared roles over at Ansible Galaxy. &nbsp;These bring you best practices, flexible configurations and in general save hours and hours of hardcore swearing and hair pulling. Each role usually supports multiple versions of multiple Linux distributions. &nbsp;However, you&#8217;ll find that the &hellip; <a href=\"https:\/\/mamchenkov.net\/wordpress\/2016\/07\/07\/forcing-amazon-linux-ami-compatibility-with-centos-in-ansible\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Forcing Amazon Linux AMI compatibility with CentOS in Ansible<\/span><\/a><\/p>\n<!-- google_ad_section_end -->\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"Forcing Amazon Linux AMI compatibility with CentOS in Ansible #ansible #sysadmin #devops #linux #Amazon #CentOS","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_links_to":"","_links_to_target":""},"categories":[1,6,133,62],"tags":[3270,3476,3383,3246,2366,2289],"keyring_services":[],"class_list":["post-26227","post","type-post","status-publish","format-standard","hentry","category-general","category-linux","category-sysadmin","category-technology","tag-amazon-aws","tag-amazon-linux-ami","tag-ansible","tag-centos-linux","tag-cloud-computing","tag-web-hosting"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":26860,"url":"https:\/\/mamchenkov.net\/wordpress\/2016\/11\/08\/install-ansible-2-0-on-amazon-ami\/","url_meta":{"origin":26227,"position":0},"title":"Install Ansible 2.0+ on Amazon AMI","author":"Leonid Mamchenkov","date":"November 8, 2016","format":false,"excerpt":"Today, while upgrading some of my Ansible roles I've hit the problem. \u00a0Some of the newer roles require Ansible 2.0. \u00a0My Amazon AMI machine that runs the playbooks was still on version 1.9. \u00a0EPEL repository doesn't seem to have the newer Ansible version yet. \u00a0Gladly, Google brough in this StackOverflow\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":28472,"url":"https:\/\/mamchenkov.net\/wordpress\/2018\/04\/08\/immutable-deployment-quorum\/","url_meta":{"origin":26227,"position":1},"title":"Immutable Deployment @ Quorum","author":"Leonid Mamchenkov","date":"April 8, 2018","format":false,"excerpt":"\"Immutable Deployment @ Quorum\" describes yet another approach to automated, and this case - immutable, deployments.\u00a0 This particular setup is slightly more on the SysAdmin\/DevOps side rather than on the development side, utilizing tools like Ansible, Amazon EC2, and Amazon AMI. If you are building very few projects, or projects\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2018\/04\/deployment-500x215.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":24075,"url":"https:\/\/mamchenkov.net\/wordpress\/2015\/05\/08\/do-not-use-amazon-linux\/","url_meta":{"origin":26227,"position":2},"title":"Do Not Use Amazon Linux","author":"Leonid Mamchenkov","date":"May 8, 2015","format":false,"excerpt":"I came across \"Do Not Use Amazon Linux\" opinion on Ex Ratione. \u00a0I have to say that I mostly agree with it. \u00a0When I initially started using Amazon Web Services, I assumed (due to time constraints mostly) that Amazon Linux was a close derivative of CentOs and I opted for\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26208,"url":"https:\/\/mamchenkov.net\/wordpress\/2016\/06\/27\/lets-encrypt-on-centos-7-and-amazon-ami\/","url_meta":{"origin":26227,"position":3},"title":"Let&#8217;s Encrypt on CentOS 7 and Amazon AMI","author":"Leonid Mamchenkov","date":"June 27, 2016","format":false,"excerpt":"The last few weeks were super busy at work, so I accidentally let a few SSL certificates expire. \u00a0Renewing them is always annoying and time consuming, so I was pushing it until the last minute, and then some. Instead of going the usual way for the renewal, I decided to\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":27263,"url":"https:\/\/mamchenkov.net\/wordpress\/2017\/01\/20\/immutable-infrastructure-with-aws-and-ansible\/","url_meta":{"origin":26227,"position":4},"title":"Immutable Infrastructure with AWS and Ansible","author":"Leonid Mamchenkov","date":"January 20, 2017","format":false,"excerpt":"Immutable infrastructure is a very powerful concept that brings stability, efficiency, and fidelity to your applications through automation and the use of successful patterns from programming. \u00a0The general idea is that you never make changes to running infrastructure. \u00a0Instead, you ensure that all infrastructure is created through automation, and to\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26931,"url":"https:\/\/mamchenkov.net\/wordpress\/2016\/11\/21\/using-ansible-to-bootstrap-an-amazon-ec2-instance\/","url_meta":{"origin":26227,"position":5},"title":"Using Ansible to bootstrap an Amazon EC2 instance","author":"Leonid Mamchenkov","date":"November 21, 2016","format":false,"excerpt":"This article - \"Using Ansible to Bootstrap My Work Environment Part 4\" is pure gold for anyone trying to figure out all the moving parts needed to automate the provisioning and configuration of the Amazon EC2 instance with Ansible. Sure, some bits are easier than the other, but it takes\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts\/26227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/comments?post=26227"}],"version-history":[{"count":0,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts\/26227\/revisions"}],"wp:attachment":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/media?parent=26227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/categories?post=26227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/tags?post=26227"},{"taxonomy":"keyring_services","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/keyring_services?post=26227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}