1
# Replace RUNNING SERVER token by server id

- hosts: servers_app
  become_user: root
  gather_facts: True
  vars:
    - running_server_token: \@\@\@_RUNNING_SERVER_\@\@\@
  tasks:
    - name: Find app js file
      become: true
      become_user: root
      shell: "ls {{ tomcat_install_base }}/webapps/{{ deployed_appl_name }}/app/app-*.js"
      register: app_js
    - debug: msg="{{ app_js.stdout }}"
    - name: Replace RUNNING SERVER token by server id
      become: true
      become_user: root
      replace:
        path: "{{ app_js.stdout }}"
        regexp: "{{ running_server_token }}"
        replace: "{{ inventory_hostname }}"

when i run the above playbook, I see the below error message. May i know whether I am doing something wrong.

all the js files do exists, but not sure why this message always.

fatal: [aps01]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "after": null,
            "attributes": null,
            "backup": false,
            "before": null,
            "content": null,
            "delimiter": null,
            "directory_mode": null,
            "encoding": "utf-8",
            "follow": false,
            "force": null,
            "group": null,
            "mode": null,
            "owner": null,
            "path": "/opt/tomcat/webapps/server-portal/app/app.bootstrap.js\n/opt/tomcat/webapps/server-portal/app/app.constants.js\n/opt/tomcat/webapps/server-portal/app/app.module.js\n/opt/tomcat/webapps/server-portal/app/app.service.js\n/opt/tomcat/webapps/server-portal/app/app.state.js",
            "regexp": "\\@\\@\\@_RUNNING_SERVER_\\@\\@\\@",
            "remote_src": null,
            "replace": "aps01",
            "selevel": null,
            "serole": null,
            "setype": null,
            "seuser": null,
            "src": null,
            "unsafe_writes": null,
            "validate": null
        }
    },
    "msg": "Path /opt/tomcat/webapps/server-portal/app/app.bootstrap.js\n/opt/tomcat/webapps/server-portal/app/app.constants.js\n/opt/tomcat/webapps/server-portal/app/app.module.js\n/opt/tomcat/webapps/server-portal/app/app.service.js\n/opt/tomcat/webapps/server-portal/app/app.state.js does not exist !",
    "rc": 257
}
techraf
  • 64,883
  • 27
  • 193
  • 198
YemGa
  • 11
  • 2
  • You should not use `stdout` directly, but `stdout_lines` in a loop. Anyway, parsing `ls` is something to avoid. Use `find` module first and iterate over the results, like in the answers and questions marked as duplicate. – techraf Aug 13 '18 at 20:54
  • Thank you, I made changes now with the find module, still some unknown errors ? Code: find: paths: "{{ tomcat_install_base }}/webapps/{{ deployed_appl_name }}/app" patterns: "app.*.js" register: app_js replace: destination: "{{ item.path }}" regexp: "{{ running_server_token }}" replace: "{{ inventory_hostname }}" with_items: "{{ app_js.files }}" Output : "msg": "Unsupported parameters for (replace) module: destination Supported parameters include: – YemGa Aug 13 '18 at 23:10
  • There is no `destination` parameter in the `replace` module. Just like the error says. https://docs.ansible.com/ansible/2.6/modules/replace_module.html – techraf Aug 14 '18 at 05:36
  • Thank you, it's actually dest i should use. – YemGa Aug 15 '18 at 19:38

0 Answers0