community.general.yarn – Manage node.js packages with Yarn

Note

This plugin is part of the community.general collection (version 4.2.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general.

To use it in a playbook, specify: community.general.yarn.

Synopsis

Requirements

The below requirements are needed on the host that executes this module.

  • Yarn installed in bin path (typically /usr/local/bin)

Parameters

Parameter Choices/Defaults Comments
executable
path
The executable location for yarn.
global
boolean
    Choices:
  • no ←
  • yes
Install the node.js library globally
ignore_scripts
boolean
    Choices:
  • no ←
  • yes
Use the --ignore-scripts flag when installing.
name
string
The name of a node.js library to install
If omitted all packages in package.json are installed.
To globally install from local node.js library. Prepend "file:" to the path of the node.js library.
path
path
The base path where Node.js libraries will be installed.
This is where the node_modules folder lives.
production
boolean
    Choices:
  • no ←
  • yes
Install dependencies in production mode.
Yarn will ignore any dependencies under devDependencies in package.json
registry
string
The registry to install modules from.
state
string
    Choices:
  • present ←
  • absent
  • latest
Installation state of the named node.js library
If absent is selected, a name option must be provided
version
string
The version of the library to be installed.
Must be in semver format. If "latest" is desired, use "state" arg instead

Examples

- name: Install "imagemin" node.js package.
  community.general.yarn:
    name: imagemin
    path: /app/location

- name: Install "imagemin" node.js package on version 5.3.1
  community.general.yarn:
    name: imagemin
    version: '5.3.1'
    path: /app/location

- name: Install "imagemin" node.js package globally.
  community.general.yarn:
    name: imagemin
    global: yes

- name: Remove the globally-installed package "imagemin".
  community.general.yarn:
    name: imagemin
    global: yes
    state: absent

- name: Install "imagemin" node.js package from custom registry.
  community.general.yarn:
    name: imagemin
    registry: 'http://registry.mysite.com'

- name: Install packages based on package.json.
  community.general.yarn:
    path: /app/location

- name: Update all packages in package.json to their latest version.
  community.general.yarn:
    path: /app/location
    state: latest

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description
changed
boolean
always
Whether Yarn changed any package data

Sample:
True
invocation
dictionary
success
Parameters and values used during execution

Sample:
{'module_args': {'executable': None, 'globally': False, 'ignore_scripts': False, 'name': None, 'path': '/some/path/folder', 'production': False, 'registry': None, 'state': 'present', 'version': None}}
msg
string
failure
Provides an error message if Yarn syntax was incorrect

Sample:
Package must be explicitly named when uninstalling.
out
string
always
Output generated from Yarn with emojis removed.

Sample:
yarn add v0.16.1[1/4] Resolving packages...[2/4] Fetching packages...[3/4] Linking dependencies...[4/4] Building fresh packages...success Saved lockfile.success Saved 1 new [email protected] Done in 0.59s.


Authors

  • David Gunter (@verkaufer)

  • Chris Hoffman (@chrishoffman), creator of NPM Ansible module)