3

brew install ansible installs the current version of Ansible (2.5.x as of this writing). I have an application that requires version 2.4, and does not work with earlier or later versions. brew search ansible results in the following:

==> Searching local taps...
ansible ✔       ansible-lint      ansible@2.0
ansible-cmdb    ansible@1.9       terraform-provisioner-ansible
==> Searching taps on GitHub...
homebrew/cask/ansible-dk
==> Searching blacklisted, migrated and deleted formulae...

Installing ansible@2.0 gives me version 2.3.

How do you install version 2.4?

Attempting to install with easy_install + pip results in this which is reportedly caused by a TLS bug with MacOS Sierra 10.12.

➜  ~ sudo easy_install pip
Searching for pip
Reading https://pypi.python.org/simple/pip/
Download error on https://pypi.python.org/simple/pip/: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) --     Some packages may not be found!
Couldn't find index page for 'pip' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
Download error on https://pypi.python.org/simple/: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) --     Some packages may not be found!
No local packages or download links found for pip
error: Could not find suitable distribution for Requirement.parse('pip')
bfontaine
  • 14,702
  • 12
  • 64
  • 87
Spencer Hill
  • 839
  • 2
  • 12
  • 30
  • Use Conda and install Ansible with pip. Enjoy saved time with your family. – techraf Jun 10 '18 at 06:36
  • 1
    Check out [Not able to install Python packages SSL: TLSV1_ALERT_PROTOCOL_VERSION](https://stackoverflow.com/questions/49768770/not-able-to-install-python-packages-ssl-tlsv1-alert-protocol-version) to resolve issues with pip installation. – hoefling Jun 10 '18 at 09:09
  • 1
    Please use the [homebrew] tag instead of [brew], which has nothing to do with that. I edited your question to fix the tag. Thanks! – bfontaine Jun 25 '18 at 09:43

1 Answers1

3

This is the way I have in my Mac:

First install python with brew: brew install python. This will install python 3.6.5:

==> Downloading https://homebrew.bintray.com/bottles/python-3.6.5.high_sierra.bottle.1.tar.gz
Already downloaded: /Users/imjoseangel/Library/Caches/Homebrew/python-3.6.5.high_sierra.bottle.1.tar.gz
==> Pouring python-3.6.5.high_sierra.bottle.1.tar.gz
==> /usr/local/Cellar/python/3.6.5/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar/
==> /usr/local/Cellar/python/3.6.5/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar/
==> /usr/local/Cellar/python/3.6.5/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar/
==> Caveats
Python has been installed as
  /usr/local/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /usr/local/opt/python/libexec/bin

If you need Homebrew's Python 2.7 run
  brew install python@2

Pip, setuptools, and wheel have been installed. To update them run
  pip3 install --upgrade pip setuptools wheel

You can install Python packages with
  pip3 install <package>
They will install into the site-package directory
  /usr/local/lib/python3.6/site-packages

See: https://docs.brew.sh/Homebrew-and-Python
==> Summary
  /usr/local/Cellar/python/3.6.5: 4,736 files, 99.2MB

From there, install virtualenv with pip3 install virtualenv:

Collecting virtualenv
  Using cached https://files.pythonhosted.org/packages/b6/30/96a02b2287098b23b875bc8c2f58071c35d2efe84f747b64d523721dc2b5/virtualenv-16.0.0-py2.py3-none-any.whl
Installing collected packages: virtualenv
  Found existing installation: virtualenv 16.0.0
    Uninstalling virtualenv-16.0.0:
      Successfully uninstalled virtualenv-16.0.0
Successfully installed virtualenv-16.0.0

Create your environment with virtualenv ansible24

Using base prefix '/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6'
New python executable in /Users/imjoseangel/Source/ansible24/bin/python3.6
Also creating executable in /Users/imjoseangel/Source/ansible24/bin/python
Installing setuptools, pip, wheel...done.

Activate your environment - source ansible24/bin/activate

And Install Ansible 2.4 - pip install ansible==2.4.0

Collecting ansible==2.4.0
  Downloading https://files.pythonhosted.org/packages/1e/7c/385ccbeb0fbefc13eaef53df76e42ef778170bdfe5fd425879735b43106e/ansible-2.4.0.0.tar.gz (6.6MB)
    100% |████████████████████████████████| 6.6MB 4.3MB/s 
Collecting jinja2 (from ansible==2.4.0)
  Using cached https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl
Collecting PyYAML (from ansible==2.4.0)
Collecting paramiko (from ansible==2.4.0)
  Using cached https://files.pythonhosted.org/packages/3e/db/cb7b6656e0e7387637ce850689084dc0b94b44df31cc52e5fc5c2c4fd2c1/paramiko-2.4.1-py2.py3-none-any.whl
Collecting cryptography (from ansible==2.4.0)
  Using cached https://files.pythonhosted.org/packages/40/87/acdcf84ce6d25a7db1c113f4b9b614fd8d707b7ab56fbf17cf18cd26a627/cryptography-2.2.2-cp34-abi3-macosx_10_6_intel.whl
Requirement already satisfied: setuptools in ./ansible24/lib/python3.6/site-packages (from ansible==2.4.0) (39.2.0)
Collecting MarkupSafe>=0.23 (from jinja2->ansible==2.4.0)
Collecting pyasn1>=0.1.7 (from paramiko->ansible==2.4.0)
  Using cached https://files.pythonhosted.org/packages/a0/70/2c27740f08e477499ce19eefe05dbcae6f19fdc49e9e82ce4768be0643b9/pyasn1-0.4.3-py2.py3-none-any.whl
Collecting bcrypt>=3.1.3 (from paramiko->ansible==2.4.0)
  Using cached https://files.pythonhosted.org/packages/7e/59/d48fd712941da1a5d6490964a37bb3de2e526965b6766273f6a7049ee590/bcrypt-3.1.4-cp36-cp36m-macosx_10_6_intel.whl
Collecting pynacl>=1.0.1 (from paramiko->ansible==2.4.0)
  Using cached https://files.pythonhosted.org/packages/74/8e/a6c0d340972d9e2f1a405aaa3f2460950b4c0337f92db0291a4355974529/PyNaCl-1.2.1-cp36-cp36m-macosx_10_6_intel.whl
Collecting cffi>=1.7; platform_python_implementation != "PyPy" (from cryptography->ansible==2.4.0)
  Using cached https://files.pythonhosted.org/packages/8e/be/40b1bc2c3221acdefeb9dab6773d43cda7543ed0d8c8df8768f05af2d01e/cffi-1.11.5-cp36-cp36m-macosx_10_6_intel.whl
Collecting asn1crypto>=0.21.0 (from cryptography->ansible==2.4.0)
  Using cached https://files.pythonhosted.org/packages/ea/cd/35485615f45f30a510576f1a56d1e0a7ad7bd8ab5ed7cdc600ef7cd06222/asn1crypto-0.24.0-py2.py3-none-any.whl
Collecting idna>=2.1 (from cryptography->ansible==2.4.0)
  Using cached https://files.pythonhosted.org/packages/27/cc/6dd9a3869f15c2edfab863b992838277279ce92663d334df9ecf5106f5c6/idna-2.6-py2.py3-none-any.whl
Collecting six>=1.4.1 (from cryptography->ansible==2.4.0)
  Using cached https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Collecting pycparser (from cffi>=1.7; platform_python_implementation != "PyPy"->cryptography->ansible==2.4.0)
Building wheels for collected packages: ansible
  Running setup.py bdist_wheel for ansible ... done
  Stored in directory: /Users/imjoseangel/Library/Caches/pip/wheels/ea/e1/f4/f5654529457978b69c0369212794664b88b51c95fa267346ea
Successfully built ansible
Installing collected packages: MarkupSafe, jinja2, PyYAML, pyasn1, pycparser, cffi, asn1crypto, idna, six, cryptography, bcrypt, pynacl, paramiko, ansible
Successfully installed MarkupSafe-1.0 PyYAML-3.12 ansible-2.4.0.0 asn1crypto-0.24.0 bcrypt-3.1.4 cffi-1.11.5 cryptography-2.2.2 idna-2.6 jinja2-2.10 paramiko-2.4.1 pyasn1-0.4.3 pycparser-2.18 pynacl-1.2.1 six-1.11.0
imjoseangel
  • 2,493
  • 2
  • 16
  • 27
  • After I restart my computer and run `source` again it complains `source: no such file or directory: ansible24/bin/activate` - is there a way to make `virtualenv ansible24` stick through restarts? – Spencer Hill Jun 10 '18 at 18:20
  • 1
    Add the `source ansible24/bin/activate` to your `.profile` file in your **home** directory – imjoseangel Jun 11 '18 at 06:02
  • So this solution seems to all work but in the end ansible --version is still reporting the wrong version. https://gist.github.com/s3w47m88/9cf25714a051c17758415fc390cc9ffd – Spencer Hill Jun 12 '18 at 01:14
  • Hi!, if your path is pointing to your main Ansible version, of course your venv will not work as expected. I recommend keeping different venvs per solution and version. I mean with solution (In my case) Ansible or ML or Module Development or Research, etc... – imjoseangel Jun 12 '18 at 05:00
  • I don't understand. Once I enter into a venv and install my ansible version isn't it automatically updating the path? When I change my ansible version outside venv it does. – Spencer Hill Jun 12 '18 at 15:56