John Cummings
John Cummings

Reputation: 2184

How do you use become when invoking a role in ansible?

How do you become a user when using a role in ansible?

For example, how would I install nodejs as root using the geerlingguy.nodejs role from ansible galaxy? Here is the relevant portion of what I have:

roles:
  - geerlingguy.nodejs
    become: yes

But that produces ERROR! Syntax Error while loading YAML on the YAML file.

Upvotes: 3

Views: 3166

Answers (1)

John Cummings
John Cummings

Reputation: 2184

I finally found a solution, which in retrospect is obvious from the documentation

roles:
    - role: geerlingguy.nodejs
      become: yes

This can also be written as:

roles:
    - { role: geerlingguy.nodejs, become: yes }

The part that was not obvious before to this ansible newbie was the alternate json-like syntax used in the documentation when it states "Also, should you wish to parameterize roles, by adding variables, you can do so, like this:"

- hosts: webservers
  roles:
    - common
    - { role: foo_app_instance, dir: '/opt/a',  app_port: 5000 }

I spent way too long figuring this out, so hopefully this answer will help someone else.

Upvotes: 7

Related Questions