How to pass option variables to ansible playbook?

2,538 views
Skip to first unread message

refrie...@gmail.com

unread,
May 14, 2017, 3:06:33 PM5/14/17
to rundeck-discuss
Hello,

I am trying to pass an job option variable to an ansible playbook and can't seem to get it working. I just installed everything the other day, here are system details:

Ubuntu: 16.04.2 LTS
Rundeck: 2.8.2-1
Ansible: 2.3.0.0
Rundeck-Ansible-Plugin: 2.0.2

Under the job options details it tells me:

The option values will be available to scripts in these forms:
Bash: $RD_OPTION_VLANID
Commandline Arguments: ${option.vlanID}
Script Content: @option.vlanID@

This is my playbook:

---
- name: Define VLAN
  hosts: all
  vars:
    vlanid: lookup('env','RD_OPTION_VLANID')
  tasks:
    - debug: msg="{{ lookup('env','RD_OPTION_VLANID') }}"
    - name: configure vlan
      connection: local
      ios_config:
        lines: vlan {{ vars.vlanid }}

Under the debug line, if I change "RD_OPTION_VLANID" to "HOME" I do see the proper home directory in the job log output. Leaving it as-is the output is blank. So it seems like Rundeck is not actually setting that envvar for the rundeck user?

I found this issue for Rundeck, but since I am executing local ansible playbooks I am not sure how it's relevant.


Thank you!

-jello

Alex Honor

unread,
May 14, 2017, 3:07:58 PM5/14/17
to rundeck...@googlegroups.com
Does the step run on a remote node? If so, make sure env vars are passed: http://rundeck.org/docs/plugins-user-guide/ssh-plugins.html#passing-environment-variables-through-remote-command

--
You received this message because you are subscribed to the Google Groups "rundeck-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rundeck-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to rundeck-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rundeck-discuss/5c322cf3-905a-4be8-abbe-e06ec9c54925%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Alex Honor

[Rundeck | a...@rundeck.com ]

refrie...@gmail.com

unread,
May 14, 2017, 4:32:42 PM5/14/17
to rundeck-discuss
No, the command runs on the local machine. Rundeck and ansible are installed on the same machine.

refrie...@gmail.com

unread,
May 14, 2017, 5:03:00 PM5/14/17
to rundeck-discuss
I figured it out. You have to manually specify the Option variables you want to pass to the playbook under the proper Step in the text box "Extra Variables".

My cleaned up playbook looks like this now:

---
- name: Define VLAN
  hosts: all
  vars:
    vlanid: "{{ vlanid }}"
  tasks:

    - name: configure vlan
      connection: local
      ios_config:
        lines: vlan {{ vars.vlanid }}

And then under Jobs > Step > Extra Variables I added this text:

vlanid: ${option.vlanID}


Reply all
Reply to author
Forward
0 new messages