@Kai Stian Olstad

On top of what we done, I have a requirement to compare shared Schema 
version comparison, updated code is below. 

Step:1 Fetch the Shared Schema version Value and register for future 
reference. 
Step:2 Stream Line CSV file and register the Output 
Step:3 Use the Streamlined CSV file and Client schema values in Column 1, 
Get the client schema Build version, these values are array of 
stdout_lines. How can I register this? 
Step:4 And use the Registered values and upgrade client schema when Shared 
Schema Version and Client Schema Version matches.(This is tricky part) 

Can I combine Step:3 and Step:4 ? Any clues. 


---

  - name: Run sqlplus command on Target DB server
    shell: source ~/.bash_profile && sqlplus -S '{{ admin }}/{{ password 
}}@{{ deploy_server }}:1521/{{ oracle_db_name }}' 
@"sharedschema_version.sql"
    args:
      chdir: roles/oracle-sql/files/
    delegate_to: localhost
    register: sharedschema_version
    tags: shared_schema

  - set_fact:
       sharedschema_version_build_number: "{{ 
sharedschema_version.stdout_lines }}"
    delegate_to: localhost

  - name: Get CSV File Content with out header
    shell: source ~/.bash_profile && awk -F',' '!/^#/ && !/^$/ && (NR!=1) { 
print }' "{{ output_csv_path }}" | sed 's/\"//g'
    register: groups_out
    delegate_to: localhost
    tags: client_schema

  - debug: var=groups_out.stdout_lines
    delegate_to: localhost

  - name: Run sqlplus command on Client DB
    shell: source ~/.bash_profile && sqlplus -S '{{ admin }}/{{ password 
}}@{{ deploy_server }}:1521/{{ oracle_db_name }}' 
@"clientschema_version.sql" {{ item.split(",").0 }}
    args:
      chdir: roles/oracle-sql/files/
    register: "clientschema_version"
    with_items: "{{ groups_out.stdout_lines }}"
    delegate_to: localhost
    tags: client_schema

  - debug: var=clientschema_version
    delegate_to: localhost

  - debug: msg="item.item={{item.item}}, item.stdout={{item.stdout}}, 
item.changed={{item.changed}}"
    with_items: "{{clientschema_version.results}}"
    delegate_to: localhost

  - name: Update the Client Schema
    shell: source ~/.bash_profile && sqlplus -S '{{ admin }}/{{ password 
}}@{{ item.split(",").3 }}' @"hotfix_client.sql" {{ item.split(",").0 }}
    with_items:
                - "{{ groups_out.stdout_lines }}"
                - "{{ clientschema_version.results }}"
    args:
      chdir: roles/oracle-sql/files/DbScripts/Scripts/
    delegate_to: localhost
    when: sharedschema_version_build_number == "{{ 
clientschema_version.stdout_lines }}"

Here is my error log 

 FAILED! => {
    "failed": true,
    "msg": "The conditional check 'sharedschema_version_build_number == 
\"{{ clientschema_version.stdout_lines }}\"' failed. The error was: error 
while evaluating conditional (sharedschema_version_build_number == \"{{ 
clientschema_version.stdout_lines }}\"): 'dict object' has no attribute 
'stdout_lines'\n\nThe error appears to have been in 
'/etc/ansible/playbooks/database/roles/oracle-sql/tasks/main.yml': line 64, 
column 5, but may\nbe elsewhere in the file depending on the exact syntax 
problem.\n\nThe offending line appears to be:\n\n\n  - name: Update the 
Client Schema\n    ^ here\n"
}





On Monday, February 26, 2018 at 12:15:27 AM UTC-6, Raja Shekar wrote:
>
> Hello Ansible Gurus,
>
> I have a CSV file as below. 
>
> "DB_SCHEMA","SYSTEM_USER","SYSTEM_PASSWORD","TNS_NAME","TNS_DESCRIPTION"
>
> "Client_Schema1","user","password","TNSNAME","(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=SANDBOX1)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))"
>
> "Client_Schema2","user","password","TNSNAME","(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=SANDBOX1)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))"
>
> "Client_Schema3","user","password","TNSNAME","(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=SANDBOX1)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))"
>
> I need to read each line of this CSV file and execute a SQL statement 
> against a Remote Database. 
>
> This is the play book, which logs in to shared DB and get the CSV file to 
> Local Ansible Master and execute Client Schema on Remote DB upgrade by 
> using the entries from Shared DB. 
>
>   - name: Run sqlplus command on {{ Shared DB }}
>     shell: source ~/.bash_profile && sqlplus -S '{{ SharedDB_username 
> }}/{{ SharedDB_password }}@{{ SharedDB_database_host }}:1521/{{ 
> SharedDB_service_name }}' 
> @"/etc/ansible/playbooks/database/roles/oracle-sql/files/final_query.sql"
>     delegate_to: localhost
>     tags: clientSchema
>
>   - name: Run powershell script
>     script: files/DecryptCsv.ps1 -InputFilePath '{{ input_csv_path }}' \
>                         -OutputFilePath '{{ output_csv_path }}' \
>                         -PassPhrase '{{ pass_phrase }}' \
>                         -SaltValue '{{ salt_value }}' \
>                         -PasswordIterations {{ password_iterations }} \
>                         -InitVector '{{ init_vector }}'
>     delegate_to: localhost
>     tags: clientSchema
>
>   - name: get CSV File Content
>     shell: source ~/.bash_profile && awk -F',' '!/^#/ && !/^$/ { print }' 
> "{{ output_csv_path }}"
>     register: groups_out
>     delegate_to: localhost
>
>   - debug: var=groups_out.stdout_lines
>
>   - name: Update the Client Schema
>     shell: source ~/.bash_profile && sqlplus -S '{{ item.1.groups_out 
> }}/{{ item.2.groups_out }}@{{ item.4.groups_out }}' 
> @"roles/oracle-sql/files/Scripts/client_hotfix.sql" {{ item.0.groups_out }}
>     sudo: no
>     with_items: "{{ groups_out.stdout_lines }}"
>
>
> Failing with below error message
>
> fatal: [10.202.98.198]: FAILED! => {"failed": true, "msg": "The task 
> includes an option with an undefined variable. The error was: 'unicode 
> object' has no attribute 'groups_out'\n\nThe error appears to have been in 
> '/etc/ansible/playbooks/database/roles/oracle-sql/tasks/main.yml': line 57, 
> column 5, but may\nbe elsewhere in the file depending on the exact syntax 
> problem.\n\nThe offending line appears to be:\n\n\n  - name: Update the 
> Schema info\n    ^ here\n\nexception type: <class 
> 'ansible.errors.AnsibleUndefinedVariable'>\nexception: 'unicode object' has 
> no attribute 'groups_out'"}
>
> And also I might need to use When condition to check particular client 
> schema and shared schema version on remote DB then only apply this hotfix. 
> it would be helpful if you guide me here to fix this issue. I tried 
> different options nothing is working for me :( 
>
>
> Thanks and Regards
> Shekar
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/c80672dd-5be5-4032-8ca2-71932f281852%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to