i have this task which should create random dir download file to the random 
dir 
but I keep getting an error on the regexp :





  
  ---
    - name: check if exists
      hosts: localhost
      gather_facts: false
      tasks:
                    - debug:
                            msg: "####################### This is start 
#######################"
    
                    - name: Handle the error
                      block:
                            - name: ansible create directory with mode 
setting example
                              vars:
                                name_dir: "{{ 1000 | random | to_uuid  }}"
                              file:
                                  path: "/home/ec2-user/backup/{{ name_dir 
}}/"
                                  state: directory
    
                            - name: Download from s3
                              vars:
                                 obj_name: "{{ 
'http://www.foo.bbb/foo/xxxx.zip' | regex_replace('^(?:\/\/|[^\/]+)*\/', 
'') }}"
                                 file_name: "{{ 
'http://www.foo.bbb/foo/xxxx.zip' | regex_search('[^\/]+$', '') }}"
                              local_action:
                                    module: aws_s3
                                    bucket: pack
                                    object: "{{ obj_name }}"
                                    dest: "/home/ec2-user/backup/{{ 
name_dir }}/{{ file_name }}"
                                    mode: get
                            - debug:
                                    msg: "################################ 
{{ obj_name }}   {{ file_name }} ##################################  {{ 
name_dir }} #####"
                      rescue:
                            - debug:
                                    msg: 'I caught an error, can do stuff 
here to fix it, :-)'






Here is the error:

   
 TASK [Download from s3] 
*********************************************************************************************************************************************************************************************************************
    task path: /home/ec2-user/backup/test7.yml:18
    Thursday 07 May 2020  16:11:59 +0000 (0:00:00.297)       0:00:00.381 
**********
    fatal: [localhost]: FAILED! =>
      msg: 'An unhandled exception occurred while templating ''{{ 
''http://www.foo.bbb/foo/xxxx.zip'' | regex_search(''[^/]+$'', '''') }}''. 
Error was a <class ''ansible.errors.AnsibleFilterError''>, original 
message: Unknown argument'




but the wired thing is that here it is working fine :

    ---
    - name: check if exsist
      hosts: localhost
      gather_facts: false
      tasks:
            - debug:
                 var: "{{ '
    obj_name: "{{ 'http://www.foo.bbb/foo/xxxx.zip' | regex_replace(
'^(?:\/\/|[^\/]+)*\/', '') }}"



-- 
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-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1b65e2c0-fa8a-4a7b-ae07-c284f1b0d88f%40googlegroups.com.

Reply via email to