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

Note

This module is part of the community.general collection (version 6.6.9).

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. You need further requirements to be able to use this module, see Requirements for details.

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

Comments

executable

path

The executable location for yarn.

global

boolean

Install the node.js library globally

Choices:

  • false ← (default)

  • true

ignore_scripts

boolean

Use the –ignore-scripts flag when installing.

Choices:

  • false ← (default)

  • true

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

Install dependencies in production mode.

Yarn will ignore any dependencies under devDependencies in package.json

Choices:

  • false ← (default)

  • true

registry

string

The registry to install modules from.

state

string

Installation state of the named node.js library

If absent is selected, a name option must be provided

Choices:

  • "present" ← (default)

  • "absent"

  • "latest"

version

string

The version of the library to be installed.

Must be in semver format. If “latest” is desired, use “state” arg instead

Attributes

Attribute

Support

Description

check_mode

Support: full

Can run in check_mode and return changed status prediction without modifying target.

diff_mode

Support: none

Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode.

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: true

- name: Remove the globally-installed package "imagemin".
  community.general.yarn:
    name: imagemin
    global: true
    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

Description

changed

boolean

Whether Yarn changed any package data

Returned: always

Sample: true

invocation

dictionary

Parameters and values used during execution

Returned: success

Sample: {"module_args": {"executable": null, "globally": false, "ignore_scripts": false, "name": null, "path": "/some/path/folder", "production": false, "registry": null, "state": "present", "version": null}}

msg

string

Provides an error message if Yarn syntax was incorrect

Returned: failure

Sample: "Package must be explicitly named when uninstalling."

out

string

Output generated from Yarn.

Returned: always

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 dependency..left-pad@1.1.3 Done in 0.59s."

Authors

  • David Gunter (@verkaufer)

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