Skip to content

Instantly share code, notes, and snippets.

@Maxdw
Last active April 10, 2018 10:07
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 Maxdw/60adbbac69bd450ef2b46aa50143b92f to your computer and use it in GitHub Desktop.
Save Maxdw/60adbbac69bd450ef2b46aa50143b92f to your computer and use it in GitHub Desktop.
ansible protobuf task ubuntu
---
# Install Google Protocol Buffers as PECL extension
# https://github.com/google/protobuf/blob/master/php/README.md
# requires php-pear, php-dev and php7.2-fpm
- pear:
name: pecl/protobuf-3.5.1.1
state: present
- name: Add protobuf extension to fpm and cli php.ini
lineinfile:
path: "/etc/php/7.2/{{ item.env }}/php.ini"
# at time of writing 09-04-2018 the regex option works per line
# so matching strings with newlines does not work
# regexp: '\n\;[a-zA-Z\s]+\nextension=[a-zA-Z0-9\/]+protobuf\.so'
# this regex will result in a new comment line on each provision
regexp: 'extension=[a-zA-Z0-9\/]+protobuf\.so'
line: "\n;Enable the protobuf PECL extension\nextension=/usr/lib/php/20170718/protobuf.so"
state: present
insertafter: EOF
with_items:
- { env: "fpm" }
- { env: "cli" }
# Install Google Protocol Compiler
# https://developers.google.com/protocol-buffers/docs/reference/php-generated
# In order to unarchive the protocol compiler the apt package 'unzip' must be installed
- name: Check for and if necessary install package "unzip"
apt:
name: unzip
state: present
- name: Ensure the /tmp/protoc target directory to unzip the protocol compiler in exists
file:
path: /tmp/protoc
state: directory
mode: 0755
group: root
owner: root
# Download and unarchive the protocol compiler
- name: Unarchive protocol compiler
unarchive:
src: https://github.com/google/protobuf/releases/download/v3.5.1/protoc-3.5.1-linux-x86_64.zip
creates: /tmp/protoc/bin
dest: /tmp/protoc
remote_src: yes
mode: 0755
group: root
owner: root
# Move binary and includes of protocol compiler to system directories
- name: Move protocol compiler bin files to /usr/local/bin/
shell: sudo mv /tmp/protoc/bin/* /usr/local/bin
args:
creates: /usr/local/bin/protoc
executable: /bin/bash
- name: Move protocol compiler include files to /usr/local/include/
shell: sudo mv /tmp/protoc/include/* /usr/local/include
args:
creates: /usr/local/include/google
executable: /bin/bash
# Chmod binary and includes of protocol compiler to system directories
- name: Chmod 0755 protocol compiler bin file '/usr/local/bin/protoc'
file:
path: /usr/local/bin/protoc
mode: 0755
- name: Chmod 0755 protocol compiler include files '/usr/local/include/google'
file:
path: /usr/local/include/google
mode: 0755
recurse: yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment