Skip to content

Instantly share code, notes, and snippets.

@halberom
Last active November 22, 2020 19:26
Show Gist options
  • Save halberom/5f0f1b499a1f3b851e6d to your computer and use it in GitHub Desktop.
Save halberom/5f0f1b499a1f3b851e6d 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