{"id":136,"date":"2016-11-27T18:34:53","date_gmt":"2016-11-27T16:34:53","guid":{"rendered":"http:\/\/www.petersplanet.nl\/?p=136"},"modified":"2016-11-27T20:18:14","modified_gmt":"2016-11-27T18:18:14","slug":"ansible","status":"publish","type":"post","link":"https:\/\/www.petersplanet.nl\/index.php\/2016\/11\/27\/ansible\/","title":{"rendered":"Getting started with Ansible"},"content":{"rendered":"<p>Ansible is a great tool to automate the repetitive tasks\u00a0on your servers. The target nodes will often be Linux but can also be Windows. The management server must be run on Linux.<br \/>\n<!--more--><\/p>\n<p><strong>Installation on a Linux CentOS 7 server<\/strong>.<br \/>\nThe Ansible binaries are in the Extra Packages for Enterprise Linux rpm (EPEL).<\/p>\n<pre>sudo yum -y update\r\nsudo yum -y wget\r\nwget\u00a0https:\/\/dl.fedoraproject.org\/pub\/epel\/epel-release-latest-7.noarch.rpm\r\nsudo rpm -iUvh\u00a0epel-release-latest-7.noarch.rpm\r\n<\/pre>\n<p>Install Ansible<\/p>\n<pre>sudo yum -y install ansible\r\nansible --version\r\n<\/pre>\n<p>Create a first playbook script.<br \/>\nAnsible works with tasks in a file called a playbook. The nodes are defined in a hosts file and can be organised in a group. The default location is in \/etc\/ansible\/hosts. Let&#8217;s add a Linux server to the Ansible hosts file.<\/p>\n<pre>[testservers]\r\n192.168.178.11\r\n<\/pre>\n<p>Check if we can reach the server.<\/p>\n<pre>ansible testservers -m ping --ask-pass --user centos\r\n<\/pre>\n<p>Create our first playbook test.yml.\u00a0Note that the position of the statements in a line are important similar as in Python.\u00a0You can use -vvvv instead of &#8211;verbose to see more debugging information.<\/p>\n<pre>- hosts: testservers\r\n  vars:\r\n    directory: \/home\/centos\r\n\r\n  tasks:\r\n  - name: Test\r\n    command: \"ls {{directory}}\"\r\n<\/pre>\n<p>And run it:<\/p>\n<pre>ansible-playbook -i \/etc\/ansible\/hosts --ask-pass --user centos test.yml --verbose\r\n<\/pre>\n<p>Or create a playbook update-servers.yml which updates your Linux server.<\/p>\n<pre>- hosts: testservers\r\n  tasks:\r\n  - name: Upgrade all packages\r\n    yum: name=* state=latest\r\n<\/pre>\n<pre>ansible-playbook --ask-pass --user centos update-servers.yml --verbose\r\n<\/pre>\n<p>In this post we only touch the surface of Ansible but it might give you an idea what is possible.<\/p>\n<p>References:<br \/>\n<a href=\"https:\/\/www.ansible.com\/\">https:\/\/www.ansible.com\/<br \/>\nhttps:\/\/docs.ansible.com\/<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ansible is a great tool to automate the repetitive tasks\u00a0on your servers. The target nodes will often be Linux but can also be Windows. The management server must be run on Linux.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-136","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/posts\/136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/comments?post=136"}],"version-history":[{"count":27,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/posts\/136\/revisions"}],"predecessor-version":[{"id":163,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/posts\/136\/revisions\/163"}],"wp:attachment":[{"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/media?parent=136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/categories?post=136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/tags?post=136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}