Monday, March 12, 2018

Ansible "mapping values are not allowed in this context" Error

Symptom:

 When we try to put 2 logic commands into 1 element, like find and copy, we hit below error
The offending line appears to be:

   - name: copy env profile script to the target
      - find:
            ^ here
exception type: <class 'yaml.scanner.ScannerError'>
exception: mapping values are not allowed in this context


The part of related yaml file are
tasks:
   - name: find and copy  env profile scripts
      - find: 
              paths: /u01/app/ansible/repository
              patterns: 'apex-ext-stg'
        register: file_to_copy
      - copy: src={{ item.path }} dest=/tmp   mode=0775
        with_items: "{{ files_to_copy.files }}" 

 Reason:

"find" and "copy" are 2 different tasks. we need to use block to group them together , or we level it up with "- name"

Solution:

- name: find and copy  env profile scripts
  block:
        - find:
               paths: /u01/app/ansible/repository
               patterns: 'test-ext-stg'
          register: file_to_copy
        - copy: src={{ item.path }} dest=/tmp  mode=0775
          with_items: "{{ files_to_copy.files }}"

or

- name: find and copy  env profile scripts part1
  find:
               paths: /u01/app/ansible/repository
               patterns: 'test-ext-stg'
  register: file_to_copy
- name: find and copy  env profile scripts part2
  copy: src={{ item.path }} dest=/tmp  mode=0775
  with_items: "{{ files_to_copy.files }}"



16 comments:

  1. Nice Post! Thank you for sharing very good post, it was so Nice to read and useful to improve my knowledge as updated one, keep blogging.
    ASW training in Electronic City

    ReplyDelete
  2. It's remarkable. The way you describe the information is awesome. This will really help me out. Thanks for sharing.
    VMware Training in Chennai
    VMware Course in Chennai
    Vmware Training center in Chennai
    Vmware Learning
    VMware Training
    Vmware cloud certification

    ReplyDelete
  3. Very nice blogs!!! i have to learning for lot of information for this sites…Sharing for wonderful information.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing, data science online training

    ReplyDelete
  4. As most of the companies are using Python as a basic programming language, there are a lot of job opportunities in Python. Thus online python programming tutorial will be very helpful for your growth in industry. The only need is to select the right course from a right place. data science course in india

    ReplyDelete
  5. List, dictionary and sets are build in data types which allow very high levels of abstraction in a language like python. angular course for beginners

    ReplyDelete
  6. data scientist course in pune with placement was never so easy and adaptable to everyone but here at Excelr We teach you numerous ways of doing Data Science Courses, which are way easy and interesting. Our experienced and expert faculty will help you reach your goal. 100% result oriented strategies are being performed; we offer Data Science Course in pune


    data scientist course in pune with placement
    Data scientist certification
    Data scientist courses

    ReplyDelete
  7. It is imperative that we read blog post very carefully. I am already done it and find that this post is really amazing.
    data scientist training and placement in hyderabad

    ReplyDelete
  8. The worst part of it was that the software only worked intermittently and the data was not accurate. You obviously canot confront anyone about what you have discovered if the information is not right. data science course in mysore

    ReplyDelete
  9. This post is very simple to read and appreciate without leaving any details out. Great work!
    data science online training in hyderabad

    ReplyDelete
  10. This is the first time I visit here. I found such a large number of engaging stuff in your blog, particularly its conversation. From the huge amounts of remarks on your articles, I surmise I am by all accounts not the only one having all the recreation here! Keep doing awesome. It has been important to compose something like this on my site and you have given me a thought.
    business analytics course in hyderabad

    ReplyDelete