0

I have an ansible playbook which looks roughly like the following. I need Zero Downtime Upgrade start and Zero Downtime Upgrade completed steps. will run once to put\remove cluser into upgrade mode. in addition I need all the tasks into Block will be run only on one node on same time and continue to next node once we get HTTP 200

Could you please review the yml file ? currently I get ERROR! 'uri' is not a valid attribute for a Block and if you have any suggestion to improve it.

---
- name: Zero Downtime Upgrade start
  hosts: atl
  serial: 1
  gather_facts: false
  vars_files:
    vars.yml
  tasks:
   - name: get Cluster state
     run_once: true
     uri:
      url: https://{{ base_url }}.XXX.com/rest/api/2/cluster/zdu/state
      headers:
       Content-Type: application/json
      force_basic_auth: true
      validate_certs: false
      user: XXX
      password: XXX
     register: response
  #  - name: debug.
  #    debug: var=response
  #    run_once: true
   - name: trigger Zero Downtime upgrade API
     run_once: true
     uri:
      url: https://{{ base_url }}.XXX.com/rest/api/2/cluster/zdu/start
      method: POST
      validate_certs: false
      headers:
       Content-Type: application/json
      force_basic_auth: true
      user: XXX
      password: XXX
      status_code: 201
#     register: response
     when: response.json.state == 'STABLE'
  #  - name: debug.
  #    run_once: true
  #    debug: var=response
   - block:
      - name: create dir for backup configuration
        file:
          path: "{{ atl_backup_conf }}"
          state: directory
          mode: '0755'
          owner: atl
          group: atl
      - name: backup configuration files
        copy:
          src: "{{ item }}"
          dest: "{{ atl_backup_conf }}"
    #      backup: true
          remote_src: true
          owner: atl
          group: atl
        with_items:
          - "{{ atl_app }}/bin/setenv.sh"
        ignore_errors: true
      - name: "stop atl service on {{ ansible_hostname }} atl node"
        #shell: /etc/init.d/atl stop
        systemd:
          name: atl
          state: stopped
        become: yes
- name: Zero Downtime Upgrade completed steps.
     hosts: atl
     vars_files:
      vars.yml
     tasks: 
     - name: trigger Zero Downtime upgrade API change to Stable status.
       run_once: true
       uri:
        url: https://{{ base_url }}.XXX.com/rest/api/2/cluster/zdu/approve
        method: POST
        validate_certs: false
        headers:
          Content-Type: application/json
        force_basic_auth: true
        user: XXX
        password: XXX
        status_code: 409 , 200

shlco
  • 1
  • 2
  • 3

1 Answers1

1

You missed a dash in front of block.

Removing all attributes your tasks look like this:

  tasks:
  - name: get Cluster state
  - name: trigger Zero Downtime upgrade API
    block:
# ^-- dash missing
      - name: "Upgrade {{ ansible_hostname }} atl node."
      - name: create dir for backup configuration
      - name: "stop atl service on {{ ansible_hostname }} atl node"
      - name: Install New atl Version.
    - name: Configure systemd service.
#   ^-- indented incorrectly
      - name: Reload Enable and Start atl.service
      - name: health checks - trigger GET node state.

As you see, block is currently an attribute for the previous task, it should be at the level of tasks instead.

Additionally, your task Configure systemd service. is not indented correctly, it should be at the same level as the other tasks.

  tasks:
  - name: get Cluster state
  - name: trigger Zero Downtime upgrade API
  - block:
# ^-- added missing dash
      - name: "Upgrade {{ ansible_hostname }} atl node."
      - name: create dir for backup configuration
      - name: "stop atl service on {{ ansible_hostname }} atl node"
      - name: Install New atl Version.
      - name: Configure systemd service.
#     ^-- indented correctly
      - name: Reload Enable and Start atl.service
      - name: health checks - trigger GET node state.

YAML is extremely picky about indentation.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
  • `- name: Zero Downtime Upgrade start hosts: atl serial: 1 gather_facts: false vars_files: vars.yml tasks: - name: trigger Zero Downtime upgrade API - block: - name: "Upgrade {{ ansible_hostname }} atl node." - name: create dir for backup configuration - name: "stop atl service atl node" - name: health checks - trigger GET node state. retries: 720 delay: 5 - name: Zero Downtime Upgrade completed steps. hosts: atl tasks: - name: trigger Zero Downtime upgrade run_once: true uri:` – shlco Nov 14 '21 at 15:44
  • thank you for your reply ,not sure how can I make it more readable in comment area.?! I need 2 first commands under tasks: will be run one time but all commands under - block: will be exec on all nodes but **node by node** and in the end again from **Upgrade completed steps.** will be run one time on one of the node. – shlco Nov 14 '21 at 15:53
  • You can't make it readable in the comments. If you have something to add to your existing question, edit it. If you encounter a new problem, it's better to accept the answer that helped you and ask a new question with the new problem. – Gerald Schneider Nov 15 '21 at 08:05
  • once I run the playbook I get the error : `ERROR! no module/action detected in task. The error appears to be in main_new.yml': line 41, column 9, but may be elsewhere in the file depending on the exact syntax problem. The offending line appears to be: - block: - name: Upgrade atl node. ^ here ` I use ansible-playbook 2.10.9 , do you sure for `- block:` module syntax ? I see there is exist `block:` with out - – shlco Nov 16 '21 at 22:54
  • Yes, [I'm sure](https://docs.ansible.com/ansible/latest/user_guide/playbooks_blocks.html). – Gerald Schneider Nov 17 '21 at 05:54
  • 1
    We can't tell you what's wrong exactly without seeing the current state of your playbook. – Gerald Schneider Nov 17 '21 at 06:17
  • unfortunately,I can't shared here because the comments not readable.any idea how can I share the current state ? – shlco Nov 17 '21 at 15:02
  • 1
    As I already told you: edit your question. Don't remove what's already in there, just add it below. – Gerald Schneider Nov 17 '21 at 15:03
  • it gave me error while try to add so I update it based on your last comment – shlco Nov 17 '21 at 16:10
  • I just want to we on same page - I need all tasks under 'get Cluster state' and 'get Cluster state' will be exec one time (run_once=true) and all the tasks inside the -block: will be exec node by node, I mean first to run all tasks on first node in atl hosts group once node is up mean I get HTTP=200 it can proceed to next node in atl hosts group and so on. once complete the '-block:' tasks can proceed and run tasks under 'Zero Downtime Upgrade completed steps.' only on one of the node (run_once=true) I hope it more clear now – shlco Nov 17 '21 at 16:28
  • thank you, I managed it. – shlco Nov 18 '21 at 07:58