2

I'm writing a playbook to manage iptables (yes, I know there is a module for this, but I prefer to use a custom playbook). After loading my new rules, I wait for a USR1 signal. If not, I make a rollback.

So, relevant ansible tasks look like this:

  - name: Restore iptables
    shell: /root/load_iptables_rules.sh
    async: 45
    poll: 0

  - name: Test SSH connection
    shell: /root/send_usr1.sh
    register: exit_code
    until: exit_code.rc == 0
    retries: 10
    async: 45
    poll: 3

I want the second task ("Test SSH Connection") to run in a new, different SSH connection. That way I can confirm that my host is really accepting new SSH connections. Otherwise, Ansible may use the already established connection, and that would not suffice my needs.

I read something about pipelining and async, but I couldn't get it working.

1 Answer 1

4

You're looking for the meta module reset_connection action; this will interrupt the connection so that following tasks will need to establish a new connection. That might look like:

- name: Restore iptables
  shell: /root/load_iptables_rules.sh
  async: 45
  poll: 0

- name: Reset connection
  meta: reset_connection

- name: Test SSH connection
  shell: /root/send_usr1.sh
  register: exit_code
  until: exit_code.rc == 0
  retries: 10
  async: 45
  poll: 3
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .