Environment="KAFKA_OPTS=-javaagent:{{jmxexporter_jar_path}}={{zookeeper_jmxexporter_port}}:{{zookeeper_jmxexporter_config_path}}"'
Environment="KAFKA_JMX_OPTS=-javaagent:/usr/share/java/kafka/jolokia.jar=port=8778,host=pilot01.test -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=pilot01.test -Dcom.sun.management.jmxremote.rmi.port=1099"
- name: append the line
lineinfile:
path: /tmp/hello.txt
backrefs: yes
regexp: '^(.*KAFKA_JMX_OPTS.*)$"'. <------------------------
line: '\1 -javaagent:{{jmxexporter_jar_path}}={{zookeeper_jmxexporter_port}}:{{zookeeper_jmxexporter_config_path}}"''
but like can we handle the if else in one line in file
this will not work when file does not have "KAFKA_JMX_OPTS" in it. Can we do it in same taks using item 2 regexp
if sting absent add entire line else if string present append it.
--- # sameer-0.yml - name: KAFKA_JMX options management hosts: localhost gather_facts: false vars: filename: sameer-0-override.conf kafka_jmx_opts: - '-javaagent:/usr/share/java/kafka/jolokia.jar=port=8778,host=pilot01.test' - '-Dcom.sun.management.jmxremote' - '-Dcom.sun.management.jmxremote.authenticate=false' - '-Dcom.sun.management.jmxremote.ssl=false' - '-Djava.rmi.server.hostname=pilot01.test' - '-Dcom.sun.management.jmxremote.rmi.port=1099' kafka_jmx_opts_str: 'KAFKA_JMX_OPTS={{ kafka_jmx_opts | join(" ") }}' tasks: - name: Manage kafka_jms_opts in override.conf ansible.builtin.lineinfile: path: '{{ filename }}' regexp: 'Environment="KAFKA_JMX_OPTS=.*"' line: 'Environment="{{ kafka_jmx_opts_str }}"' state: present create: true # You should have "owner:", "group:", and "mode:" here too.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/73e8499f-c1f0-4183-88c7-4a55b034b161n%40googlegroups.com.
-- Todd