{"id":1468,"date":"2018-11-01T18:49:22","date_gmt":"2018-11-01T17:49:22","guid":{"rendered":"http:\/\/www.netnea.com\/cms\/?p=1468"},"modified":"2018-11-01T16:03:22","modified_gmt":"2018-11-01T15:03:22","slug":"auto-upgrade-pip-in-ansible-role-task","status":"publish","type":"post","link":"https:\/\/www.netnea.com\/cms\/2018\/11\/01\/auto-upgrade-pip-in-ansible-role-task\/","title":{"rendered":"auto-upgrade pip in Ansible role\/task"},"content":{"rendered":"<p>Lets say you have an Ansible role in which you create a virtual-environment using Python 3.x:<\/p>\n<div>\n<pre>- name: Install python venv and requirements\r\n  environment:\r\n    http_proxy: http:\/\/proxy.domain.com:8080\r\n    https_proxy: http:\/\/proxy.domain.com:8080\r\n    HTTP_PROXY: http:\/\/proxy.domain.com:8080\r\n    HTTPS_PROXY: http:\/\/proxy.domain.com:8080\r\n  pip:\r\n    extra_args: '--trusted-host pypi.python.org'\r\n    requirements: \/path\/to\/requirements.txt\r\n    virtualenv: \/path\/to\/venv\r\n    virtualenv_command: \/opt\/python-3.7.0\/bin\/python3.7 -m venv\r\n<\/pre>\n<p>If your requirements.txt only contains the modules you really need for your app, you end up with an old pip version (10.x). And then, when you do a pip freeze, you get this ugly message:<\/p>\n<\/div>\n<pre>You are using pip version 10.0.1, however version 18.1 is available.\r\nYou should consider upgrading via the 'pip install --upgrade pip' command.\r\n<\/pre>\n<p>Not really nice, uuhh ? The fix is simple: add the required pip release to your requirements.txt, e.g.<\/p>\n<pre># requirements.txt\r\n...\r\npip&gt;=18.1\r\n...<\/pre>\n<p>Fixed !<\/p>\n<p>And if you wonder why I made my pip module config so complex&#8230; it&#8217;s because Ansible insist to use pip2, which is not really appropriate for Python 3.x venv&#8217;s. This is the case with Ansible 2.6.2.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lets say you have an Ansible role in which you create a virtual-environment using Python 3.x: &#8211; name: Install python venv and requirements environment: http_proxy: http:\/\/proxy.domain.com:8080 https_proxy: http:\/\/proxy.domain.com:8080 HTTP_PROXY: http:\/\/proxy.domain.com:8080 HTTPS_PROXY: http:\/\/proxy.domain.com:8080 pip: extra_args: &#8216;&#8211;trusted-host pypi.python.org&#8217; requirements: \/path\/to\/requirements.txt virtualenv: \/path\/to\/venv virtualenv_command: \/opt\/python-3.7.0\/bin\/python3.7 -m venv If your requirements.txt only contains the modules you really need for [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,3],"tags":[45,46],"class_list":{"0":"post-1468","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-linux","7":"category-nms","8":"tag-ansible","9":"tag-python-3","10":"czr-hentry"},"_links":{"self":[{"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/posts\/1468","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/comments?post=1468"}],"version-history":[{"count":8,"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/posts\/1468\/revisions"}],"predecessor-version":[{"id":1476,"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/posts\/1468\/revisions\/1476"}],"wp:attachment":[{"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/media?parent=1468"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/categories?post=1468"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/tags?post=1468"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}