Skip to content

Instantly share code, notes, and snippets.

@vmoravec
Forked from halberom/play.yml
Created November 28, 2017 22:06
Show Gist options
  • Save vmoravec/935b66d2f11b5ca094384318690859b3 to your computer and use it in GitHub Desktop.
Save vmoravec/935b66d2f11b5ca094384318690859b3 to your computer and use it in GitHub Desktop.
ansible - example of command and with_items
---
- hosts: foo
vars:
gems:
libxml-ruby: { version: 2.6.0, state: present, include_dependencies: yes, user_install: no }
shenzhen: { version: 0.13.1, state: present, include_dependencies: yes, user_install: no }
gem_executable: /usr/local/rvm/ruby/blah/blah/1.2/gem
tasks:
- name: install a bunch of gems - warning, use the right executable and run as the right user!
gem:
name: "{{ item.key }}"
version: "{{ item.version | default(omit) }}"
state: "{{ item.state | default(omit) }}"
include_dependencies: "{{ item.include_dependencies | default(omit) }}"
user_install: "{{ item.user_install | default(omit) }}"
executable: "{{ gem_executable }}"
with_dict: gems
- name: Install stupid ruby gems with shell commands
sudo_user: automationman
command: bash -lc "gem install {{ item }}"
with_items:
- libxml-ruby-2.6.0
- shenzhen-0.13.1
- activesupport -v 4.1.8"
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment