{"id":2987,"date":"2014-10-24T12:41:50","date_gmt":"2014-10-24T10:41:50","guid":{"rendered":"http:\/\/supportex.net\/blog\/?p=2987"},"modified":"2019-05-10T14:16:39","modified_gmt":"2019-05-10T12:16:39","slug":"ansible-installing-pyenv-centos","status":"publish","type":"post","link":"https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/","title":{"rendered":"Ansible: installing pyenv on Centos"},"content":{"rendered":"<p>In <a href=\"http:\/\/supportex.net\/blog\/2014\/09\/installing-python-2-7-centos-6-5\/\">one<\/a> of our previous post we covered how to install Python 2.7 on Centos using <a href=\"https:\/\/github.com\/yyuu\/pyenv\">pyenv<\/a>\u00a0which is a Python versions management tool. Today we will show how to use ansible to do that for you. \u00a0(If you are on Ubuntu you might want to check\u00a0<a href=\"https:\/\/github.com\/avanov\/ansible-galaxy-pyenv\">ansible-galaxy-pyenv\u00a0<\/a>.) Manual installation process is described <a href=\"https:\/\/github.com\/yyuu\/pyenv#installation\">here<\/a>. This is how it looks like:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">git clone git:\/\/github.com\/yyuu\/pyenv.git .pyenv\necho 'export PYENV_ROOT=\"$HOME\/.pyenv\"' &gt;&gt; ~\/.bash_profile\necho 'export PATH=\"$PYENV_ROOT\/bin:$PATH\"' &gt;&gt; ~\/.bash_profile\necho 'eval \"$(pyenv init -)\"' &gt;&gt; ~\/.bash_profile\nexec $SHELL\npyenv install 2.7.6\npyenv rehash\n<\/pre>\n<p>Pretty simple. But why bother to do it on each server command by command if you can use ansible?<\/p>\n<p>It&#8217;s supposed you have some user (we use <em>devops<\/em>) which is able to log in to our target host (<em>example.com<\/em>) and is also able to run commands as root via sudo.<\/p>\n<p>Here&#8217;s how to do that using a playbook:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">- hosts:  example.com\n  user: devops\n  vars:\n      home: home\/devops\n\n  tasks:\n  - name: pyenv | check pyenv installed\n    command: test -x {{ home }}\/.pyenv\/bin\/pyenv\n    register: pyenv_present\n    ignore_errors: yes\n\n  - name: pyenv | install devel packages\n    sudo: yes\n    yum:\n        pkg: \"{{ item }}\"\n        state: present\n    with_items:\n        - gcc\n        - patch\n        - sqlite-devel\n        - readline-devel\n        - openssl-devel\n\n# http:\/\/hakunin.com\/six-ansible-practices\n  - name: ensure github.com is a known host\n    lineinfile:\n      dest: \"{{ home }}\/.ssh\/known_hosts\"\n      create: yes\n      state: present\n      line: \"{{ lookup('pipe', 'ssh-keyscan -t rsa github.com') }}\"\n      regexp: \"^github\\\\.com\"\n\n  - name: pyenv | update pyenv repo\n    git:  repo=git:\/\/github.com\/yyuu\/pyenv.git dest=\"{{ home }}\/.pyenv\/\"\n    when: pyenv_present|failed\n    ignore_errors: yes\n\n  - name: define environment variable 1 \n    shell: echo 'export PYENV_ROOT=\"$HOME\/.pyenv\"' &gt;&gt; \"{{ home }}\/.bash_profile\"\n    when: pyenv_present|failed\n\n  - name: define environment variable 2\n    shell: echo 'export PATH=\"$PYENV_ROOT\/bin:$PATH\"' &gt;&gt; \"{{ home }}\/.bash_profile\"\n    when: pyenv_present|failed\n   \n  - name: add pyenv init to your shell to enable shims and autocompletion.\n    shell: echo 'eval \"$(pyenv init -)\"' &gt;&gt; \"{{ home }}\/.bash_profile\"\n    when: pyenv_present|failed\n\n  - name: install python versions into $PYENV_ROOT\/versions\n    sudo: no\n    shell: \" . {{ home }}\/.bash_profile &amp;&amp;  pyenv install 2.7.6\"\n    when: pyenv_present|failed\n\n  - name: rebuild the shim binaries\n    sudo: no\n    shell: \" . {{ home }}\/.bash_profile &amp;&amp; pyenv rehash\"\n    when: pyenv_present|failed\n\n  - name: list installed ruby version\n    sudo: no\n    shell: \" . {{ home }}\/.bash_profile &amp;&amp; pyenv versions  \"\n    register: py_versions\n\n  - debug: var=py_versions\n\n<\/pre>\n<p>Check:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">ansible-playbook install_pyenv.yml -vvv  -s --check<\/code><\/p>\n<p>and run:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">ansible-playbook install_pyenv.yml -vvv  -s<\/code><\/p>\n<p>After it&#8217;s done you can start using Python 2.7 on Centos:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">[devops@example.com ~]$ python -V\nPython 2.7.6\n[devops@example.com ~]$\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In one of our previous post we covered how to install Python 2.7 on Centos using pyenv\u00a0which is a Python versions management tool. Today we will show how to use ansible to do that for you. \u00a0(If you are on Ubuntu you might want to check\u00a0ansible-galaxy-pyenv\u00a0.) Manual installation process is described here. This is how&hellip; <\/p>\n<div class=\"readmore-wrapper\"><a href=\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/\" class=\"more-link\">Read <\/a><\/div>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[152],"tags":[155,275,153],"class_list":["post-2987","post","type-post","status-publish","format-standard","hentry","category-linux","tag-ansible","tag-linux","tag-pyenv"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Ansible: installing pyenv on Centos &#8211; Supportex.NET blog<\/title>\n<meta name=\"description\" content=\"How to use ansible for installing pyenv on CentOS 6.5. Ansible install pyenv on CentOS. Ansible setup pyenv on CentOS.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Ansible: installing pyenv on Centos &#8211; Supportex.NET blog\" \/>\n<meta property=\"og:description\" content=\"How to use ansible for installing pyenv on CentOS 6.5. Ansible install pyenv on CentOS. Ansible setup pyenv on CentOS.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/\" \/>\n<meta property=\"og:site_name\" content=\"Supportex.NET blog\" \/>\n<meta property=\"article:published_time\" content=\"2014-10-24T10:41:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-05-10T12:16:39+00:00\" \/>\n<meta name=\"author\" content=\"Oleksii Tykhonov\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Oleksii Tykhonov\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/\"},\"author\":{\"name\":\"Oleksii Tykhonov\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251\"},\"headline\":\"Ansible: installing pyenv on Centos\",\"datePublished\":\"2014-10-24T10:41:50+00:00\",\"dateModified\":\"2019-05-10T12:16:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/\"},\"wordCount\":139,\"commentCount\":0,\"keywords\":[\"ansible\",\"linux\",\"pyenv\"],\"articleSection\":[\"linux\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/\",\"url\":\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/\",\"name\":\"Ansible: installing pyenv on Centos &#8211; Supportex.NET blog\",\"isPartOf\":{\"@id\":\"https:\/\/supportex.net\/blog\/en\/#website\"},\"datePublished\":\"2014-10-24T10:41:50+00:00\",\"dateModified\":\"2019-05-10T12:16:39+00:00\",\"author\":{\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251\"},\"description\":\"How to use ansible for installing pyenv on CentOS 6.5. Ansible install pyenv on CentOS. Ansible setup pyenv on CentOS.\",\"breadcrumb\":{\"@id\":\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/supportex.net\/blog\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Ansible: installing pyenv on Centos\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#website\",\"url\":\"https:\/\/supportex.net\/blog\/en\/\",\"name\":\"Supportex.NET blog\",\"description\":\"Server and network management company\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/supportex.net\/blog\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251\",\"name\":\"Oleksii Tykhonov\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4fd5f58002717075c88963469b9babef?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4fd5f58002717075c88963469b9babef?s=96&d=mm&r=g\",\"caption\":\"Oleksii Tykhonov\"},\"url\":\"https:\/\/supportex.net\/blog\/author\/oleksiitykhonov\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Ansible: installing pyenv on Centos &#8211; Supportex.NET blog","description":"How to use ansible for installing pyenv on CentOS 6.5. Ansible install pyenv on CentOS. Ansible setup pyenv on CentOS.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/","og_locale":"en_US","og_type":"article","og_title":"Ansible: installing pyenv on Centos &#8211; Supportex.NET blog","og_description":"How to use ansible for installing pyenv on CentOS 6.5. Ansible install pyenv on CentOS. Ansible setup pyenv on CentOS.","og_url":"https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/","og_site_name":"Supportex.NET blog","article_published_time":"2014-10-24T10:41:50+00:00","article_modified_time":"2019-05-10T12:16:39+00:00","author":"Oleksii Tykhonov","twitter_misc":{"Written by":"Oleksii Tykhonov","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/#article","isPartOf":{"@id":"https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/"},"author":{"name":"Oleksii Tykhonov","@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251"},"headline":"Ansible: installing pyenv on Centos","datePublished":"2014-10-24T10:41:50+00:00","dateModified":"2019-05-10T12:16:39+00:00","mainEntityOfPage":{"@id":"https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/"},"wordCount":139,"commentCount":0,"keywords":["ansible","linux","pyenv"],"articleSection":["linux"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/","url":"https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/","name":"Ansible: installing pyenv on Centos &#8211; Supportex.NET blog","isPartOf":{"@id":"https:\/\/supportex.net\/blog\/en\/#website"},"datePublished":"2014-10-24T10:41:50+00:00","dateModified":"2019-05-10T12:16:39+00:00","author":{"@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251"},"description":"How to use ansible for installing pyenv on CentOS 6.5. Ansible install pyenv on CentOS. Ansible setup pyenv on CentOS.","breadcrumb":{"@id":"https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/supportex.net\/blog\/2014\/10\/ansible-installing-pyenv-centos\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/supportex.net\/blog\/en\/"},{"@type":"ListItem","position":2,"name":"Ansible: installing pyenv on Centos"}]},{"@type":"WebSite","@id":"https:\/\/supportex.net\/blog\/en\/#website","url":"https:\/\/supportex.net\/blog\/en\/","name":"Supportex.NET blog","description":"Server and network management company","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/supportex.net\/blog\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251","name":"Oleksii Tykhonov","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4fd5f58002717075c88963469b9babef?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4fd5f58002717075c88963469b9babef?s=96&d=mm&r=g","caption":"Oleksii Tykhonov"},"url":"https:\/\/supportex.net\/blog\/author\/oleksiitykhonov\/"}]}},"_links":{"self":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts\/2987","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/comments?post=2987"}],"version-history":[{"count":4,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts\/2987\/revisions"}],"predecessor-version":[{"id":3116,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts\/2987\/revisions\/3116"}],"wp:attachment":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/media?parent=2987"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/categories?post=2987"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/tags?post=2987"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}