rundeck-plugins / ansible-plugin

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

Asking about com.batix.rundeck.plugins.AnsiblePlaybookWorflowNodeStep and ansible-disable-limit: 'false' #307

Open r0039 opened 2 years ago

r0039 commented 2 years ago

Hi, Firstly, I would like to thank for your contribution :-)

Now I am having an issue. Somehow rundeck var could not pass into Ansible playbook. I am using the type: com.batix.rundeck.plugins.AnsiblePlaybookWorflowNodeStep.

Here is my code: /rundeck/templates/ansible/se/jira/redeploy_jira.yaml

- description: Run redeploy of Jira nodes
  group: ansible/se/redeploy
  name: {{name}}_redeploy_jira
  multipleExecutions: true
  nodefilters:
    dispatch:
      excludePrecedence: true
      keepgoing: false
      threadcount: 1
    filter: '.*jira.*'
  nodesSelectedByDefault: true
  options:
    - delimiter: ','
      description: Skip selected Ansible tags
      enforced: true
      multivalued: true
      name: tags.skip
      values:
        - dns
        - indexing
        - deploy
        - terminate
        - slack
    - name: new_hostname
      description: Choose the new opengrok instance which is different from the instance in Node Selector
      enforced: true
      required: true
      value: 'jira01'
      values:
        - jira01
        - jira02
    - name: indexing_timeout
      description: Timeout limit for a opengrok indexing in seconds
      regex: ^\d+
      value: '21600'
      required: true
    - name: poll_interval
      description: The period to poll the status of indexing
      regex: ^\d+
      required: true
      value: '600'
  scheduleEnabled: true
  sequence:
    commands:
    - configuration:
        ansible-base-dir-path: {{ ansible_base }}/{{ gitflow_branch }}
        ansible-disable-limit: 'false'
        ansible-extra-param: '{{ ansible_inventories }} --skip-tags "${option.tags.skip}"'
        ansible-extra-vars: |-
          new_hostname: ${option.new_hostname}
          old_hostname: '${node.name}'
          indexing_timeout: ${option.indexing_timeout}
          poll_interval: ${option.poll_interval}
          rundeck: true
        ansible-playbook: /playbooks/se/redeploy/jira/redeploy.yaml
      nodeStep: true
      type: com.batix.rundeck.plugins.AnsiblePlaybookWorflowNodeStep
    keepgoing: false
    strategy: node-first

/ansible/playbooks/se/redeploy/jira/redeploy.yaml

- name: "Stage 1  - Run deploy (terraform) {{ new_hostname }}"
  import_playbook: ../../../../playbooks/all/automerge.yaml
  vars:
    action: deploy
    terragrunt_module: "components/opengrok"
    terragrunt_environment: 'pc/ci-eu'
    node_name: "{{ new_hostname }}"
  tags: deploy
  register: result

- debug:
    var: result
    verbosity: 2

- hosts: localhost
  gather_facts: no

  vars:
    new_hostname_fqdn: "{{ groups[new_hostname][0] }}"
    old_hostname_fqdn: "{{ groups[old_hostname][0] }}"
    dns_alias: "opengrok"
    dns_zone: "intgdc.com"
    rundeck: false
    indexing_timeout: "{{ 6 * 3600 }}"
    poll_interval: "{{ 10 * 60 }}"
  vars_files:
    - ../shared/common_vars.yml

My idea: I want to use nodefilters of rundeck job, then I pass its value into old_hostname: '${node.name}'. Thus I change:

  1. The type from type: com.batix.rundeck.plugins.AnsiblePlaybookWorkflowStep to type: com.batix.rundeck.plugins.AnsiblePlaybookWorflowNodeStep
  2. enable nodeStep: true.

Implementation In rundeck UI, I input new_hostname and select old_hostname from Change the Target Nodes.

It works! However, new_hostname could not pass into Ansible Playbook. Also, I already declared this one ansible-disable-limit: 'false', but --limit still existed.

log
procArgs: [ansible-playbook, /playbooks/se/redeploy/jira/redeploy.yaml, -l, jira02.na.example.com
...
...

14:33:32 |   |   | [WARNING]: Could not match supplied host pattern, ignoring: jira02.na.example.com
14:33:32 |   |   | ERROR! Specified hosts and/or --limit does not match any hosts
14:33:32 |   |   | Failed: AnsibleNonZero: ERROR: Ansible execution returned with non zero code.

My question: Can I use new_hostname and old_hostname on this case? Canansible-disable-limit: 'false'work withtype: com.batix.rundeck.plugins.AnsiblePlaybookWorflowNodeStepandnodeStep: true`?

I spend a lot of time, but still could not solve this issue. I am appreciate your help. Thanks a lot!

simon-c-msc commented 1 year ago

Hi,

com.batix.rundeck.plugins.AnsiblePlaybookWorflowNodeStep is designed (just like all other node steps) to be executed on each node selected in the node filter.

Therefore, the plugin uses the --limit option by design (when you run in debug mode you can see the ansible-playbook command passed with all the parameters).

Targeting multiple hosts in a playbook inside a Node step is not possible since Rundeck will limit it to the node it's executing on.

To accomplish what you want you would need:

  1. Have a fully functional ansible inventory
  2. Use a workflow step with limit disabled
  3. Set the job to execute locally
  4. Target new_hostname and old_hostname inside your ansible playbook file directly (you can pass those values from Rundeck options to extra-vars)