Skip to content

source

The source attribute reads content from a local file or an HTTP(S) URL. An ordinary definition must use exactly one of source, exec, or value.

Local and remote content can be narrowed with parser and selector. Direct value definitions and interactive sources return raw content instead of using the generic parser/selector pipeline.

Special sources

  • <getpass> prompts for a value without echoing it in the terminal.
  • <stdin> writes a prompt to STDERR and reads one line from standard input.
  • http://... and https://... sources are fetched with an HTTP GET request.
  • env:NAME uses the value of an environment variable as the local path or URL.

env: references

env:NAME must be the complete attribute value; it is not string interpolation. Env Alias first looks for NAME in the current process environment, then in values generated by earlier definitions. Definitions are evaluated top-to-bottom, so define a value before a same-file env: reference to it.

env: references are supported in source, value, parser, selector, keepass_password, and ansible_vault_password. If a definition uses name to rename itself, reference its effective name, not its YAML key.

Example - simple

Read line 5 from /proc/cpuinfo into EXAMPLE.

env-alias:
  EXAMPLE:
    source: "/proc/cpuinfo"
    selector: 5

Example - getpass

Prompt for a value without echoing it.

env-alias:
  EXAMPLE:
    source: "<getpass>"

Example - stdin

Read one visible line from standard input.

env-alias:
  EXAMPLE:
    source: "<stdin>"

Example - home path

Read from a file under the user's home directory. ~ is expanded for local-file sources.

env-alias:
  AWS_ACCESS_KEY_ID:
    source: "~/.aws/credentials"
    parser: ini
    selector: "profile_name.aws_access_key_id"

Example - HTTP source

Fetch a JSON value from an HTTP(S) endpoint.

env-alias:
  EXAMPLE:
    source: "https://api.github.com/repos/threatpatrols/env-alias"
    selector: "default_branch"

Example - env reference

Use an earlier definition to supply a source path.

env-alias:
  EXAMPLE_SOURCE:
    value: "/proc/cpuinfo"
  EXAMPLE:
    source: "env:EXAMPLE_SOURCE"
    selector: 5