rundeck-plugins / ansible-plugin

Ansible Integration for Rundeck
MIT License
331 stars 100 forks source link

Can not run playbook with options. #7

Closed zwxk14 closed 8 years ago

zwxk14 commented 8 years ago

Only can specify the path to the playbook.

frozenice commented 8 years ago

Can you give an example of what options you mean? The standard options like -C and -D?

zwxk14 commented 8 years ago

Yes, The ansible-playbook standard options like:

  • -e VARS, --extra-vars=VARS
  • -t, TAGS, --tags=TAGS
  • --skip-tags=SKIP_TAGS

The options above are very useful for playbooks.

frozenice commented 8 years ago

Can you take a look if this is satisfied by v1.2.0 for now?

sperlic commented 8 years ago

What is the correct way to use --extra-vars? Tried -e,somevar=true,-e,someothervar=false but variables are not visible within playbooks. I get errors from Ansible about undefined variables.

frozenice commented 8 years ago

@sperlic try it like this: -e var1=True var2=5

sperlic commented 8 years ago

@frozenice Unfortunately I already tried on that and many other ways but no cigar. I always get "msg": "'var1' is undefined"

frozenice commented 8 years ago

Hm, seems to work for me. I created a job with one node step (Ansible Playbook).

Contents of /tmp/test-playbook:

---
- hosts: all
  tasks:
    - debug: msg="var1 {{ var1 }}, var2 {{ var2 }}"

Running the job on a node yields this log output in Rundeck:

Using /etc/ansible/ansible.cfg as config file
PLAY ***************************************************************************

TASK [setup] *******************************************************************
ok: [somenode]

TASK [debug] *******************************************************************
ok: [somenode] => {
    "msg": "var1 True, var2 5"
}

PLAY RECAP *********************************************************************
somenode                       : ok=2    changed=0    unreachable=0    failed=0

What are you doing differently?

sperlic commented 8 years ago

I additionally use rolls and tags in combination with extra vars. Here are the steps to reproduce the problem

Create eg. ansible directory structure like this

/tmp/ansible/
├── roles
│   └── test-playbook
│       └── tasks
│           └── main.yml
└── test-playbook.yml

test-playbook.yml

---
- hosts: all
  roles:
    - { role: test-playbook, tags: tag1 }

roles/test-playbook/tasks/main.yml

---
- debug: 
    msg: "tag1, var1 {{ var1 }}, var2 {{ var2 }}"
  tags:
    - tag1 

- debug: 
    msg: "tag2, var1 {{ var1 }}, var2 {{ var2 }}"
  tags:
    - tag2 

Create job with one node step (Ansible playbook)

and try following Extra Arguments

Output with Extra Arguments: -t tag2 -e var1=True var2=5 or -t tag1,tag2 -e var1=True var2=5

Using /etc/ansible/ansible.cfg as config file
PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
ok: [somenode]

PLAY RECAP *********************************************************************
somenode                : ok=1    changed=0    unreachable=0    failed=0   

Output with Extra Arguments: -t,tag1 -e var1=True var2=5

Using /etc/ansible/ansible.cfg as config file
PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
ok: [somenode]

TASK [test-playbook : debug] ***************************************************
fatal: [somenode]: FAILED! => {"failed": true, "msg": "'var1' is undefined"}

NO MORE HOSTS LEFT *************************************************************
    to retry, use: --limit @/tmp/ansible/test-playbook.retry

PLAY RECAP *********************************************************************
somenode                : ok=1    changed=0    unreachable=0    failed=1   

Execution failed: 160: [Workflow result: , step failures: {1=Dispatch failed on 1 nodes: [somenode: AnsibleNonZero: Ansible exited with non-zero code.]}, Node failures: {somenode=[AnsibleNonZero: Ansible exited with non-zero code.]}, status: failed]

Also combinations like -t,tag1,tag2,-e var1=True var2=5 does not work, but it seems that -e var1=True var2=5 -t tag1,tag2 is right combination.

Using /etc/ansible/ansible.cfg as config file
PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
ok: [somenode]

TASK [test-playbook : debug] ***************************************************
ok: [somenode] => {
    "msg": "tag1, var1 True, var2 5"
}

TASK [test-playbook : debug] ***************************************************
ok: [somenode] => {
    "msg": "tag2, var1 True, var2 5"
}

PLAY RECAP *********************************************************************
somenode                : ok=3    changed=0    unreachable=0    failed=0 

Thank you for following me.

sperlic commented 8 years ago

It seems that still does not work as expected. When using extra arguments -e var1=True var2=5 -t tag2 will run the whole playbook instead tasks tagged with tag2.

frozenice commented 8 years ago

Have you tried running it manually via Ansible? ansible-playbook /tmp/ansible/test-playbook.yml -l somenode -e "var1=True var2=5" -t tag2 Or something like this. Does it do what you want? I tried it briefly, but couldn't get a correct result with your example.

sperlic commented 8 years ago

Yes and it and works, here's output

$ ansible-playbook /tmp/ansible/test-playbook.yml  -l somenode -t tag2 -e 'var1=True var2=5'

PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
ok: [somenode]

TASK [test-playbook : debug] ***************************************************
ok: [somenode] => {
    "msg": "tag2, var1 True, var2 5"
}

PLAY RECAP *********************************************************************
somenode                 : ok=2    changed=0    unreachable=0    failed=0   

What result you get? Is there anything missing in the steps to reproduce the problem?

frozenice commented 8 years ago

tag2 seems to work, but try tag1 - it runs both tags for me. If I remove , tags: tag1 from the playbook it looks good. I don't know if it is supposed to work that way - I haven't played enough with Ansible, yet.

Doesn't seem to work in Rundeck, though. I guess the extra parameters get messed up when passed to Ansible, due to spaces or whatnot. Need to take a closer look at my AnsibleRunner later.

sperlic commented 8 years ago

That should work in that way, -t tag1 is tag for playbook role and tag2 should be separated. In this example tagged role does not make much sense but it is useful when the playbook is more complex. Sorry for the confusion and thanks for accepted bug.

frozenice commented 8 years ago

I changed the extraArgs handling a bit. Can you please try again with the latest version?

sperlic commented 8 years ago

I tried with extra arguments -t tag2 -e var1=True var2=5 but it did not help.

Using /etc/ansible/ansible.cfg as config fileERROR! the playbook: var2=5 could not be found

Execution failed: 179: [Workflow result: , step failures: {1=Dispatch failed on 1 nodes: [somenode: AnsibleNonZero: Ansible exited with non-zero code.]}, Node failures: {somenode=[AnsibleNonZero: Ansible exited with non-zero code.]}, status: failed]
frozenice commented 8 years ago

Have you tried this manually with Ansible? I think you need to wrap those extra args in quotes, if you have multiple. Try: -t tag2 -e "var1=True var2=5"

sperlic commented 8 years ago

Extra arguments have more sense now, works flawlessly. Thanks.

frozenice commented 8 years ago

Awesome! :) Closing this now, feel free to open a new issue for anything else.