我有一个 ansible playbook,大致如下所示。我需要零停机升级开始和零停机升级完成步骤。将运行一次以将\删除群集置于升级模式。此外,我需要将所有任务放入堵塞将在同一时间仅在一个节点上运行,一旦我们获得 HTTP 200,将继续在下一个节点上运行
您能检查一下 yml 文件吗?目前我得到了错误!‘uri’ 不是块的有效属性如果您有任何改进建议。
---
- 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
答案1
您漏掉了 前面的一个破折号block
。
删除所有属性后您的任务如下所示:
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.
如你所见,block
目前是上一个任务的属性,它应该处于的级别tasks
。
此外,您的任务Configure systemd service.
缩进不正确,它应该与其他任务处于同一级别。
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 对于缩进非常挑剔。