Commit 613107af authored by Reimar Stier's avatar Reimar Stier

Add conda installer role

parent 4754954d
[defaults] [defaults]
roles_path=roles:local_roles roles_path=roles:local_roles
lookup_plugins=lookup_plugins
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
---
# defaults file for conda_installer
\ No newline at end of file
---
# handlers file for conda_installer
\ No newline at end of file
#!/usr/bin/env python #!/usr/bin/env python
import datetime
import json
import re import re
from ansible.module_utils.urls import open_url from ansible.module_utils.urls import open_url
from ansible.plugins.lookup import LookupBase from ansible.plugins.lookup import LookupBase
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from pprint import pprint
import datetime
URL_ANACONDA = "https://repo.anaconda.com/archive/" URL_ANACONDA = "https://repo.anaconda.com/archive/"
URL_MINICONDA = "https://repo.continuum.io/miniconda/" URL_MINICONDA = "https://repo.continuum.io/miniconda/"
...@@ -14,11 +14,11 @@ PATTERN_PYTHON = re.compile( ...@@ -14,11 +14,11 @@ PATTERN_PYTHON = re.compile(
RELEASE_MAX_AGE_DAYS = 365 RELEASE_MAX_AGE_DAYS = 365
def main(): def fetch_miniconda_releases(architecture="x86_64", python_version="3", release_max_age_days=RELEASE_MAX_AGE_DAYS):
request = open_url(url=URL_MINICONDA, method="GET") request = open_url(url=URL_MINICONDA, method="GET")
response = request.read() response = request.read()
data = [] data = {}
soup = BeautifulSoup(response, "html.parser") soup = BeautifulSoup(response, "html.parser")
table = soup.find('table') table = soup.find('table')
rows = table.find_all('tr') rows = table.find_all('tr')
...@@ -35,25 +35,31 @@ def main(): ...@@ -35,25 +35,31 @@ def main():
"python": result.group("python"), "python": result.group("python"),
"version": result.group("version"), "version": result.group("version"),
"os": result.group("os"), "os": result.group("os"),
"arch": result.group("arch") "arch": result.group("arch"),
"download": "{base}{filename}".format(base=URL_MINICONDA, filename=release["Filename"])
} }
release.update(info) release.update(info)
timestamp = datetime.datetime.strptime(release["Last Modified"], "%Y-%m-%d %H:%M:%S") timestamp = datetime.datetime.strptime(release["Last Modified"], "%Y-%m-%d %H:%M:%S")
if (now - timestamp).days > RELEASE_MAX_AGE_DAYS: if (now - timestamp).days > release_max_age_days:
continue continue
if release["os"] == "Linux" and release['arch'] == 'x86_64' and release["python"] == "3": if release["os"] == "Linux" and release['arch'] == architecture and release["python"] == python_version:
data.append(release) data[release["version"]] = release
# find actual latest version number
latest_item = [item for item in data.values() if item["version"] == "latest"]
latest_version = [item for item in data.values() if
item["MD5"] == latest_item[0]["MD5"] and item["version"] != "latest"]
latest_version_str = latest_version[0]["version"]
# update latest version number in map
data["latest"]["version"] = latest_version_str
return data
latest_item = [item for item in data if item["version"] == "latest"]
latest_version = [item for item in data if item["MD5"] == latest_item[0]["MD5"]]
pprint(data)
download_url = "{base}{filename}".format(base=URL_MINICONDA, filename=latest_version[0]["Filename"]) class LookupModule(LookupBase):
checksum_md5 = latest_version[0]["MD5"] def run(self, terms, variables=None, **kwargs):
print(latest_version[0]["version"]) return [json.dumps(fetch_miniconda_releases())]
print(download_url)
print(checksum_md5)
if __name__ == '__main__': if __name__ == '__main__':
main() print(json.dumps(fetch_miniconda_releases(), indent=4))
galaxy_info:
author: your name
description: your description
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
min_ansible_version: 2.4
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
\ No newline at end of file
---
# tasks file for conda_installer
- name: Install beautiful soup python package
package:
name: ["python-bs4", "python3-bs4"]
state: present
- name: Check Conda installation - name: Check Conda installation
stat: stat:
path: /opt/miniconda3 path: /opt/miniconda3
get_checksum: false get_checksum: false
register: check_conda register: check_conda
- name: Lookup recent version of conda
set_fact:
conda_releases: "{{ lookup('conda_releases') }}"
- name: Show conda releases
debug: msg="{{ conda_releases }}"
- name: Install Conda - name: Install Conda
block: block:
- name: Download Miniconda - name: Download Miniconda
......
---
- hosts: localhost
remote_user: root
roles:
- conda_installer
\ No newline at end of file
---
# vars file for conda_installer
\ No newline at end of file
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
- {role: 'jetbrains_installer', tags: ['jetbrains']} - {role: 'jetbrains_installer', tags: ['jetbrains']}
- {role: 'webofmars.xfce4-desktop', tags: ['desktop']} - {role: 'webofmars.xfce4-desktop', tags: ['desktop']}
- {role: 'base', tags: ['base']} - {role: 'base', tags: ['base']}
- {role: 'conda_installer', tags: ['conda']}
post_tasks: post_tasks:
- import_tasks: tasks/xfce4_configuration.yml - import_tasks: tasks/xfce4_configuration.yml
tags: desktop_config tags: desktop_config
- import_tasks: tasks/install_conda.yml
tags: conda
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment