Merge pull request #48 from generoi/issue-36

Issue #36: Add option to install npm/composer/pip/gem packages
This commit is contained in:
Jeff Geerling 2017-06-07 16:40:48 -05:00 committed by GitHub
commit 1af9802b9b
4 changed files with 73 additions and 1 deletions

View file

@ -25,7 +25,7 @@ This is a work in progress, and is mostly a means for me to document my current
### Running a specific set of tagged tasks
You can filter which part of the provisioning process to run by specifying a set of tags using `ansible-playbook`'s `--tags` flag. The tags available are `dotfiles`, `homebrew`, `mas` and `osx`.
You can filter which part of the provisioning process to run by specifying a set of tags using `ansible-playbook`'s `--tags` flag. The tags available are `dotfiles`, `homebrew`, `mas`, `extra-packages` and `osx`.
ansible-playbook main.yml -i inventory -K --tags "dotfiles,homebrew"
@ -46,6 +46,21 @@ You can override any of the defaults configured in `default.config.yml` by creat
- { id: 557168941, name: "Tweetbot" }
- { id: 497799835, name: "Xcode" }
composer_packages:
- name: hirak/prestissimo
- name: drush/drush
version: '^8.1'
gem_packages:
- name: bundler
state: latest
npm_packages:
- name: webpack
pip_packages:
- name: mkdocs
Any variable can be overridden in `config.yml`; see the supporting roles' documentation for a complete list of available variables.
## Included Applications / Configuration (Default)

View file

@ -76,5 +76,25 @@ mas_password: ""
osx_script: "~/.osx --no-restart"
# Install packages from other package managers.
# Note: You are responsible for making sure the required package managers are
# installed, eg. through homebrew.
composer_packages: []
# - name: drush
# state: present # present/absent, default: present
# version: "^8.1" # default: N/A
gem_packages: []
# - name: bundler
# state: present # present/absent/latest, default: present
# version: "~> 1.15.1" # default: N/A
npm_packages: []
# - name: webpack
# state: present # present/absent/latest, default: present
# version: "^2.6" # default: N/A
pip_packages: []
# - name: mkdocs
# state: present # present/absent/latest, default: present
# version: "0.16.3" # default: N/A
# Glob pattern to ansible task files to run after all other tasks are finished.
post_provision_tasks: []

View file

@ -34,6 +34,9 @@
when: configure_osx
tags: ['osx']
- include: tasks/extra-packages.yml
tags: ['extra-packages']
- name: Run configured post-provision ansible task files.
include: "{{ outer_item }}"
loop_control:

34
tasks/extra-packages.yml Normal file
View file

@ -0,0 +1,34 @@
---
- name: Install global Composer packages.
composer:
command: "{{ (item.state | default('present') == 'absent') | ternary('remove', 'require') }}"
arguments: "{{ item.name | default(item) }} {{ item.version | default('@stable') }}"
# Ansible 2.4 supports `global_command` making `working_dir` optional.
working_dir: "{{ lookup('env', 'COMPOSER_HOME') | default('~/.composer', true) }}"
with_items: "{{ composer_packages }}"
- name: Install global NPM packages.
npm:
name: "{{ item.name | default(item) }}"
state: "{{ item.state | default('present') }}"
version: "{{ item.version | default(omit) }}"
global: yes
executable: "{{ item.executable | default(omit) }}"
with_items: "{{ npm_packages }}"
- name: Install global Pip packages.
pip:
name: "{{ item.name | default(item) }}"
state: "{{ item.state | default('present') }}"
version: "{{ item.version | default(omit) }}"
executable: "{{ item.executable | default(omit) }}"
with_items: "{{ pip_packages }}"
- name: Install global Ruby gems.
gem:
name: "{{ item.name | default(item) }}"
state: "{{ item.state | default('present') }}"
version: "{{ item.version | default(omit) }}"
user_install: no
executable: "{{ item.executable | default(omit) }}"
with_items: "{{ gem_packages }}"