Call async_status & python script in one task (Failed error message)

39 views
Skip to first unread message

Neha Singh

unread,
Feb 21, 2023, 3:29:50 AM2/21/23
to Ansible Project
Hi Team,

Below are the two tasks which I am including in playbook. Main agenda is that, when my packages are installing, at that time rather than just getting  waiting or retried message, I wanted some customised message to print as well. That xustomized message, I am retrieving from python script (in 2nd task)

- name: Ensure packages are installed
  yum:
    name:
      - xorg-x11-server*
      - dhcp
      - bind
      - vsftpd
      - dovecot
    state: present
  async: 86400 #24 hours
  poll: 0
  register: yum_installer

- name: Waiting for yum package installation to complete
  async_status: jid={{ yum_installer.ansible_job_id }}
  shell: python /opt/ibm/si/saas/ansible/test_neha.py
  register: console_job_results
  until: console_job_results.finished
  retries: 100
  delay: 10


But I am getting the error ERROR! conflicting action statements: shell, async_status here. Can you please suggest something, what should be the next thing to do here. I really need some customised message to print, which I am retrieving from python script. Is there any way to include both async_status & python script module in one task.

Thanks 
Neha Singh

Atul Nasir

unread,
Aug 23, 2023, 2:43:44 AM8/23/23
to Ansible Project
---
- name: Ensure packages are installed and display custom message
  hosts: your_target_hosts
  tasks:

    - name: Ensure packages are installed
      yum:
        name:
          - xorg-x11-server*
          - dhcp
          - bind
          - vsftpd
          - dovecot
        state: present
      async: 86400
      poll: 0
      register: yum_installer

    - name: Display custom message using a handler
      debug:
        msg: "Custom message from Python script: {{ console_job_results.msg }}"
      when: yum_installer.status == 'running'
      async_status: jid={{ yum_installer.ansible_job_id }}
      register: console_job_results
      retries: 100
      delay: 10

  handlers:
    - name: Display custom message when yum installation is complete
      debug:
        msg: "Custom message from Python script: {{ console_job_results.msg }}"
      when: yum_installer.status == 'successful'
Reply all
Reply to author
Forward
0 new messages