Skip to content

Instantly share code, notes, and snippets.

@virantha
Last active April 3, 2019 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save virantha/1b1352c0290b39718596d2bb6891b8bb to your computer and use it in GitHub Desktop.
Save virantha/1b1352c0290b39718596d2bb6891b8bb to your computer and use it in GitHub Desktop.
rpi setup ansible
- hosts: all
remote_user: pi
become_method: sudo
vars_prompt:
- name: new_password
prompt: "Enter the password you would like to use for the user pi"
confirm: yes
tasks:
- name: backup shadow file
copy:
remote_src: yes
src: /etc/shadow
dest: /tmp/shadow
become: yes
- name: generate hash pass
delegate_to: localhost
command: python -c "from passlib.hash import md5_crypt; import getpass; print (md5_crypt.hash('{{new_password}}'))"
register: hash
- debug:
var: hash.stdout
- name: update password
user:
name: pi
password: '{{hash.stdout}}'
become: yes
[pi]
raspberrypi.local ansible_user=pi
- hosts: all
remote_user: pi
become_method: sudo
vars:
PYTHON: "3.7.2"
OPEN_SSL: openssl-1.0.2g
build_path: "{{ansible_env.HOME}}/build"
HOME: "{{ansible_env.HOME}}"
tasks:
- name: Update APT package cache
apt: update_cache=yes
become: yes
- name: Update packages
apt: upgrade=dist
become: yes
- name: Install build-essential
package: name="build-essential" state=present
become: yes
- name: Install build packages
apt:
state: present
name:
- tk-dev
- libncurses5-dev
- libncursesw5-dev
- libreadline6-dev
- libdb5.3-dev
- libgdbm-dev
- libsqlite3-dev
- libssl-dev
- libbz2-dev
- libexpat1-dev
- liblzma-dev
- zlib1g-dev
- libffi-dev
- uuid-dev
- vim
- git
- python-pip
- screen
become: yes
- name: Ensure build directory exists
file:
path: "{{ build_path }}"
state: directory
recurse: yes
- name: Download openssl
get_url:
url: "https://www.openssl.org/source/{{ OPEN_SSL }}.tar.gz"
dest: "{{ build_path }}/{{ OPEN_SSL }}.tar.gz"
mode: "755"
register: openssl_download
- name: Untar openssl
unarchive:
remote_src: yes
src: "{{ build_path }}/{{ OPEN_SSL }}.tar.gz"
dest: "{{ build_path }}"
when: openssl_download.changed
- name: configure openssl
command: ./config shared --prefix=/usr/local
args:
chdir: "{{ build_path }}/{{ OPEN_SSL }}"
when: openssl_download.changed
- name: make openssl
command: make -j 4
args:
chdir: "{{ build_path }}/{{ OPEN_SSL }}"
register: make_openssl
when: openssl_download.changed
- name: install openssl
command: make install
args:
chdir: "{{ build_path }}/{{ OPEN_SSL }}"
become: yes
when: make_openssl.changed
- name: set /etc/ld.so.conf.d to add /usr/local/
lineinfile:
path: /etc/ld.so.conf.d/openssl.conf
create: yes
line: "/usr/local/lib"
become: yes
- name: run ldconfig to update dynamic link lib path to use /usr/local/lib
command: ldconfig
become: yes
- name: Download python 3.7
get_url:
url: "https://www.python.org/ftp/python/{{PYTHON}}/Python-{{PYTHON}}.tgz"
dest: "{{ build_path }}/Python-{{ PYTHON }}.tgz"
mode: "755"
register: python_download
- name: Untar python
unarchive:
remote_src: yes
src: "{{ build_path }}/Python-{{ PYTHON }}.tgz"
dest: "{{ build_path }}"
when: python_download.changed
- name: Uncomment SSL
blockinfile:
path: "{{ build_path}}/Python-{{ PYTHON }}/Modules/Setup.dist"
insertbefore: "#SSL=/usr/local/ssl"
block: |
SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
- name: configure python
command: ./configure --enable-optimizations --with-openssl=/usr/local --prefix=/usr/local
args:
chdir: "{{ build_path }}/Python-{{ PYTHON }}"
when: python_download.changed
register: python_configure
- name: make python
shell: make -j 4'
args:
chdir: "{{ build_path }}/Python-{{ PYTHON }}"
register: make_python
when: python_configure.changed
- name: install python
shell: make altinstall'
args:
chdir: "{{ build_path }}/Python-{{ PYTHON }}"
become: yes
when: python_configure.changed
- name: Setup .bashrc
blockinfile:
path: "{{ HOME }}/.bashrc"
block: |
export VIRTUALENVWRAPPER_PYTHON="/usr/local/bin/python3.7"
source /usr/local/bin/virtualenvwrapper.sh
- name: Install pip virtualenv
pip:
executable: /usr/local/bin/pip3.7
name:
- virtualenv
- virtualenvwrapper
become: yes
- name: pip install bricknil
pip:
name:
- bricknil
virtualenv: "{{ HOME }}/.virtualenvs/bricknil"
virtualenv_python: python3.7
- name: git clone bricknil
git:
repo: 'https://github.com/virantha/bricknil.git'
dest: '{{ HOME }}/bricknil'
clone: yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment