Score:0

Ansible playbook to post message into kafka topic

cn flag
Playbook 1:
---
- name: Message into topic
  hosts: web1
  become: yes
  tasks:
    - name: post message
      expect:
        shell: "/usr/local/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic testTopic"
        responses:
          Question:
            - "Hi there"
        

Playbook 2:

- name: Message into topic
  hosts: web1
  gather_facts: false
  tasks:
    - name: post message
      shell:
        command: /usr/local/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic testTopic
        responses:                    
          (?i)Message: "Hello From Playbook"
  

Tried with the above two playbooks and ended up with some errors. Unable to find a proper solution for this. [enter image description here][1]

root@ip-172-31-83-195:/usr/local/kafka# bin/kafka-console-producer.sh --broker-list localhost:9092 --topic testTopic

hello there Hi there

This was the command I am trying to run in the playbook. If you have any examples that can take to other prompt like above command(ctrl+c is to come out of the prompt). Please let me know how we can use them in the playbook. Thanks in advance!

Errors:

Error: For Playbook 1

root@ip-172-31-87-7:~# ansible-playbook Playbook_to_post_message_into_the_topic.yaml

PLAY [Message into topic] ***********************************************************************************************************************************

TASK [post message] *****************************************************************************************************************************************
fatal: [172.31.83.195]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "changed": true, "cmd": "/bin/bash -c \"/usr/local/kafka/bin/kafka-console-producer.sh --broker-list 54.87.252.89:9092 --topic testTopic\"", "delta": "0:00:30.407263", "end": "2022-02-16 08:32:24.990783", "msg": "non-zero return code", "rc": 129, "start": "2022-02-16 08:31:54.583520", "stdout": ">[2022-02-16 08:32:07,214] WARN [Producer clientId=console-producer] Bootstrap broker 54.87.252.89:9092 (id: -1 rack: null) disconnected (org.apache.kafka.clients.NetworkClient)\r\n[2022-02-16 08:32:24,532] WARN [Producer clientId=console-producer] Bootstrap broker 54.87.252.89:9092 (id: -1 rack: null) disconnected (org.apache.kafka.clients.NetworkClient)", "stdout_lines": [">[2022-02-16 08:32:07,214] WARN [Producer clientId=console-producer] Bootstrap broker 54.87.252.89:9092 (id: -1 rack: null) disconnected (org.apache.kafka.clients.NetworkClient)", "[2022-02-16 08:32:24,532] WARN [Producer clientId=console-producer] Bootstrap broker 54.87.252.89:9092 (id: -1 rack: null) disconnected (org.apache.kafka.clients.NetworkClient)"]}

PLAY RECAP **************************************************************************************************************************************************
172.31.83.195              : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

Error: for Playbook 2

PLAY [Message into topic] ***********************************************************************************************************************************

TASK [post message] *****************************************************************************************************************************************
fatal: [172.31.83.195]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "changed": false, "msg": "Unsupported parameters for (command) module: command, responses Supported parameters include: _raw_params, _uses_shell, argv, chdir, creates, executable, removes, stdin, stdin_add_newline, strip_empty_ends, warn"}

PLAY RECAP **************************************************************************************************************************************************
172.31.83.195              : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
ALex_hha avatar
cn flag
Where is the error itself ?
cn flag
Thanks for the response @ALex_hha , added the errors below. As the command will take to other prompt. So not sure how it is gona suppose to be written in playbook.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.