[ansible-project] Re: How to get desired data from JSON

2022-03-22 Thread dmc...@gmail.com

JSON isn't my strong point but I can pull out the individual elements and 
you wanted to create the msg. Hopefully this will help you to complete what 
you're trying to do.

TASK [debug] 
**
ok: [localhost] => {
"msg": "*jdbc_data_source name is cwds has username CAN_USER and jndi 
name cwdsjndi*"
}

This is the playbook:

---
- name: ReadJsonfile
  hosts: localhost
  tasks:
  - name: Display the JSON file content
shell: "cat file.json"
register: result

  - name: debug
set_fact:
  result1: "{{ result.stdout | from_json }}"

  - name: debug
debug:
  msg: "jdbc_data_source name is {{ 
result1[1].jdbc_data_source[3].jdbc_data_source_params.jndi_name }} has 
username {{ 
result1[1].jdbc_data_source[2].jdbc_driver_params[2].properties.property[1].value
 
}} and jndi name {{ result1[1].jdbc_data_source[1].name }}"

Good Luck
-

On Tuesday, 22 March 2022 at 05:01:03 UTC knowy...@gmail.com wrote:

> I need to print the below for any `jdbc_data_source` found
>
> expected output:
>
> jdbc_data_source name is  has username  and jndi name 
> 
>
> which will print as
>
> jdbc_data_source name is `cwds` has username  `CAN_USER`  and jndi name `
> cwdsjndi`
>
>
> Here is my JSON:
>
> [
>   {
> "?xml": {
>   "attributes": {
> "encoding": "UTF_8",
> "version": "1.0"
>   }
> }
>   },
>   {
> "jdbc_data_source": [
>   {
> "attributes": {
>   "xmlns": "http://xmlns.oracle.com/weblogic/jdbc_data_source;
> }
>   },
>   {
> "name": "cwdsjndi"
>   },
>   {
> "jdbc_driver_params": [
>   {
> "url": "jdbc:oracle:thin:@//myhost.myshop.com:1521/OLTT206"
>   },
>   {
> "driver_name": "oracle.jdbc.OracleDriver"
>   },
>   {
> "properties": {
>   "property": [
> {
>   "name": "user7"
> },
> {
>   "value": "CAN_USER"
> }
>   ]
> }
>   },
>   {
> "password_encrypted": 
> "{AES}BcqmURyYoCkLvC5MmREXsfpRMO93KPIubqUAbb95+nE="
>   }
> ]
>   },
>   {
> "jdbc_data_source_params": {
>   "jndi_name": "cwds"
> }
>   }
> ]
>   },
>   {
> "?xml": {
>   "attributes": {
> "encoding": "UTF_8",
> "version": "1.0"
>   }
> }
>   },
>   {
> "jdbc_data_source": [
>   {
> "attributes": {
>   "xmlns": "http://xmlns.oracle.com/weblogic/jdbc_data_source;
> }
>   },
>   {
> "name": "dsvelcw"
>   },
>   {
> "jdbc_driver_params": [
>   {
> "url": "jdbc:oracle:thin:@myhost.myshop.com:1521:DB01"
>   },
>   {
> "driver_name": "oracle.jdbc.OracleDriver"
>   },
>   {
> "properties": {
>   "property": [
> {
>   "name": "user"
> },
> {
>   "value": "WEB_USER"
> }
>   ]
> }
>   },
>   {
> "password_encrypted": 
> "{AES}WYImLDLo0j7S80cGMUDsE5M5QTnpffTPGyIzDuGG6WU="
>   }
> ]
>   },
>   {
> "jdbc_data_source_params": {
>   "jndi_name": "dsvelcw"
> }
>   }
> ]
>   }
> ]
>
> All I could achieve so far is to read the json and loop over it as below:
>
> ---
>   - name: ReadJsonfile
> hosts: localhost
> tasks:
>   - name: Display the JSON file content
> shell: "cat my.json"
> register: result
>
>   - name: save the Json data to a Variable as a Fact
> set_fact:
>   jsondata: "{{ result.stdout | from_json }}"
>  
>   - name: create YML for server name with DB
> debug:
>   msg: "{{ item }}"
> loop: "{{ jsondata }}"
> loop_control:
>   pause: 20
>   
> I then tried several attempts to read the specific elements but had no 
> success.
>
> Can you please suggest?
>
>
>

-- 
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/74f86230-1c88-4000-ae4a-5ab2d13d466bn%40googlegroups.com.


[ansible-project] Ansible: Can you register the Linux banner without logging in?

2022-03-22 Thread dmc...@gmail.com


I'm trying to capture the linux banner you see before you login to a Linux 
server - using Ansible. I don't want to login to the server, just get the 
banner. I was hoping to use register to save it, then use part of it's 
contents as a conditional for which tasks to run.

Is this possible?

I originally tried to just run a remote command and capture the output, but 
I only get the output of the command and not the banner so it's a little 
more tricky to do than I first thought.

I.E: A standard banner:
WARNING : Unauthorized access to this system is forbidden and will be 
prosecuted by law. By accessing this system, you agree that your actions 
may be monitored if unauthorized usage is suspected. MANAGED by SYSTEM-A 

So if I find "MANAGED by SYSTEM-A" in the banner, I run specific tasks and 
specific host variables. If it isn't managed by system-a, I run the same 
tasks but use different host variables.

This would form part of a set of pre-tasks within Ansible before the main 
playbooks and roles are run.

What I'm seeing is the banner is probably discarded as rubbish by Ansible 
but there may be an output plugin I could use to save the contents?

Hopefully I've explained what I'm trying to do and someone has maybe done 
this previously.
Thanks for your help.

-- 
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/9359a3e6-6645-45e7-bbad-20b99a33010an%40googlegroups.com.


Re: [ansible-project] How ansible vault is safe when using scripts?

2022-03-22 Thread Abhijeet Kasurde
You can use this
https://docs.ansible.com/ansible/latest/user_guide/vault.html?extIdCarryOver=true_cid=701f201Css5AAC#storing-passwords-in-third-party-tools-with-vault-password-client-scripts

On Tue, Mar 22, 2022 at 4:45 PM Stefan Hornburg (Racke) 
wrote:

> On 22/03/2022 12:05, R Batchen wrote:
> > Hey,
> > I dont understand how ansible vault is safe if i want to use in a
> script  i need to give ansible
> > the file where the password  is saved in plain text.. so i dont get it
> >
> > i do get it being safe if i do a prompts for the password with
> --ask-vault-pass
> > but when i point to ansible using --vault-password-file or export global
> variable with pass it is saved on the system\file as plain text
> >
> > what am i missing?
>
> You can use a GPG encrpyted password file with a wrapper script.
>
> Regards
> Racke
>
> >
> > Thanks!
> >
> > --
> > 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  ansible-project+unsubscr...@googlegroups.com>.
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/4ae3f1e6-f4c0-4214-b0a4-d2c5208dcfd6n%40googlegroups.com
> <
> https://groups.google.com/d/msgid/ansible-project/4ae3f1e6-f4c0-4214-b0a4-d2c5208dcfd6n%40googlegroups.com?utm_medium=email_source=footer
> >.
>
>
> --
> Automation expert - Ansible and friends
> Linux administrator & Debian maintainer
> Perl Dancer & conference hopper
>
> --
> 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/918761a2-9f59-b7db-860a-f3d4456a58d3%40linuxia.de
> .
>


-- 
Thanks,
Abhijeet Kasurde

-- 
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/CAFwWkHoTUcFESTexGa6gMsY%3Du-1aQ7%2BM%3DDJaAOqKC%3Dw-_3d1iw%40mail.gmail.com.


Re: [ansible-project] How ansible vault is safe when using scripts?

2022-03-22 Thread Stefan Hornburg (Racke)

On 22/03/2022 12:05, R Batchen wrote:

Hey,
I dont understand how ansible vault is safe if i want to use in a script  i 
need to give ansible
the file where the password  is saved in plain text.. so i dont get it

i do get it being safe if i do a prompts for the password with --ask-vault-pass
but when i point to ansible using --vault-password-file or export global 
variable with pass it is saved on the system\file as plain text

what am i missing?


You can use a GPG encrpyted password file with a wrapper script.

Regards
   Racke



Thanks!

--
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/4ae3f1e6-f4c0-4214-b0a4-d2c5208dcfd6n%40googlegroups.com
 
.



--
Automation expert - Ansible and friends
Linux administrator & Debian maintainer
Perl Dancer & conference hopper

--
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/918761a2-9f59-b7db-860a-f3d4456a58d3%40linuxia.de.


OpenPGP_signature
Description: OpenPGP digital signature


[ansible-project] How ansible vault is safe when using scripts?

2022-03-22 Thread R Batchen
Hey,
I dont understand how ansible vault is safe if i want to use in a script  i 
need to give ansible
the file where the password  is saved in plain text.. so i dont get it

i do get it being safe if i do a prompts for the password with 
--ask-vault-pass
but when i point to ansible using --vault-password-file or export global 
variable with pass it is saved on the system\file as plain text

what am i missing?

Thanks!

-- 
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/4ae3f1e6-f4c0-4214-b0a4-d2c5208dcfd6n%40googlegroups.com.