Try the attached Python script.

But probably you just have the wrong number of spaces for indentation.

Try:

---
  - hosts: node02
    vars:
      ORACLE_BASE: /u01/oracle/product
      ORACLE_HOME: /u01/oracle/product/11.2.0
    remote_user: oracle
    sudo_user: root
    sudo: false
    gather_facts: true
    tasks:
      - name: export ORACLE_HOME
        action: shell export ORACLE_HOME={{ ORACLE_HOME }};


But also be advised that you can specify the environment directly in your 
playbook. First question in the FAQ
(http://docs.ansible.com/ansible/faq.html)



Am 13.11.2016 um 17:28 schrieb Shaikh Abdul:
> Hi Experts,
> 
> My export.yml is failing,please correct me
> 
> 
> [oracle@node02 ~]$ cat export.yml
> ---
>   - hosts: node02
>   vars:
>     ORACLE_BASE: /u01/oracle/product
>     ORACLE_HOME: /u01/oracle/product/11.2.0
>     remote_user: oracle
>     sudo_user: root
>     sudo: false
>     gather_facts: true
>   tasks:
>   - name: export ORACLE_HOME
>   action: shell export ORACLE_HOME={{ ORACLE_HOME }};
> 
> ********************************************************************************
> [oracle@node02 ~]$ ansible-playbook -i hosts -k export.yml
> SSH password:
> ERROR! Syntax Error while loading YAML.
> 
> 
> The error appears to have been in '/home/oracle/export.yml': line 3, column 
> 3, but may
> be elsewhere in the file depending on the exact syntax problem.
> 
> The offending line appears to be:
> 
>   - hosts: node02
>   vars:
>   ^ here
> 
> Regards,
> Abdul
> 
> -- 
> 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
> [email protected] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/5e2d2fb4-203b-45a6-9bc6-ef095588abc4%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/5e2d2fb4-203b-45a6-9bc6-ef095588abc4%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/c5701d33-079c-c866-2009-76f7b6c52ddc%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
#!/usr/bin/env python2
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import os
import sys
import traceback
import yaml


def exit_usage():
    print('Usage %s <yaml file or directory>' % sys.argv[0])
    sys.exit(1)

def validate(filename):
    print('Validating %s' % filename)
    try:
        tpl = yaml.load(open(filename).read())
    except Exception:
        print(traceback.format_exc())
        return 1
    # yaml is OK, now walk the parameters and output a warning for unused ones
    for p in tpl.get('parameters', {}):
        str_p = '\'%s\'' % p
        in_resources =  str_p in str(tpl.get('resources', {}))
        in_outputs =  str_p in str(tpl.get('outputs', {}))
        if not in_resources and not in_outputs:
            print('Warning: parameter %s in template %s appears to be unused'
                  % (p, filename))

    return 0

if len(sys.argv) < 2:
    exit_usage()

path_args = sys.argv[1:]
exit_val = 0
failed_files = []

for base_path in path_args:
    if os.path.isdir(base_path):
        for subdir, dirs, files in os.walk(base_path):
            for f in files:
                if f.endswith('.yaml'):
                    file_path = os.path.join(subdir, f)
                    failed = validate(file_path)
                    if failed:
                        failed_files.append(file_path)
                    exit_val |= failed
    elif os.path.isfile(base_path) and base_path.endswith('.yaml'):
        failed = validate(base_path)
        if failed:
            failed_files.append(base_path)
        exit_val |= failed
    else:
        print('Unexpected argument %s' % base_path)
        exit_usage()

if failed_files:
    print('Validation failed on:')
    for f in failed_files:
        print(f)
else:
    print('Validation successful!')
sys.exit(exit_val)

Reply via email to