Skip to content

Commit

Permalink
Merge pull request geerlingguy#48 from generoi/issue-36
Browse files Browse the repository at this point in the history
Issue geerlingguy#36: Add option to install npm/composer/pip/gem packages
  • Loading branch information
geerlingguy authored Jun 7, 2017
2 parents 489ee9b + 02cd32a commit 1af9802
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions default.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
3 changes: 3 additions & 0 deletions main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
34 changes: 34 additions & 0 deletions tasks/extra-packages.yml
Original file line number Diff line number Diff line change
@@ -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 }}"

0 comments on commit 1af9802

Please sign in to comment.