简体   繁体   中英

ansible rolling restart playboook

Folks, I'd like to have a service be restarted individually on each host, and wait for user input before continuing onto the next host in the inventory.

Currently, if you have the following:

- name: Restart something
  command: service foo restart
  tags:
    - foo
- name: wait
  pause: prompt="Make sure org.foo.FooOverload exception is not present"
  tags:
    - foo

It will only prompt once, and not really have the effect desired.

What is the proper ansible syntax to wait for user input before running the restart task on each host?

Use a combination of serial attribute and step option of a playbook.

playbook.yml

- name: Do it
  hosts: myhosts
  serial: 1

  tasks:
  - shell: hostname 

Call the playbook with --step option

ansible-playbook playbook.yml --step

You will be prompted for every host.

    Perform task: shell hostname (y/n/c): y

    Perform task: shell hostname (y/n/c):  **************************************** 
    changed: [y.y.y.y]
    Perform task: shell hostname (y/n/c): y

    Perform task: shell hostname (y/n/c):  **************************************** 
    changed: [z.z.z.z]

For more information: Start and Step

I went ahead with this:

- name: Restart Datastax Agent
  tags:
    - agent
  hosts: cassandra
  sudo: yes
  serial: 1
  gather_facts: yes
  tasks:
    - name: Pause
      pause: prompt="Hit RETURN to restart datastax agent on {{ inventory_hostname }}"
    - name: Restarting Datastax Agent on {{ inventory_hostname }}
      service: name=datastax-agent state=restarted

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM