[ansible-project] Re: config management play for weblogic KIE server

2023-02-20 Thread Sohail Jaffer
Hello,
  I need help in with getting my play-book to parse data that is 
coming back from Ansible URI Response using "ansible.builtin.uri" module, 
trying to parse data json saved as var=result.  But I keep seeing the 
following message, saying variable is not defined ! 'dict object has no 
attribute 'json'.  The play-book come back with no syntax error nor any 
failures just this message below.

Message:
"result.json.data": "VARIABLE IS NOT DEFINED!: 'dict object' has no 
attribute 'json'"


see below:

$ cat uricall.yml
---
- name: Validate KIE Server deployment
  hosts:  all
  become: false
  gather_facts: false
  vars:
ansible_python_interpreter: /opt/bin/python
kie_server_server: "http://reqres.in/api/users?page=2;
kie_server_endpoint: "/kie-server/services/rest/server/containers"
kie_server_port: ":13421"
kieserver_user: "user"
kieserver_password: "somepassword"
expected_server_version: "7.72.0.Final"
  tasks:
- name: list details
  ansible.builtin.uri:
url: "{{ kie_server_server }}{{ kie_server_port }}{{ 
kie_server_endpoint }}"
user: "{{ kieserver_user }}"
password: "{{ kieserver_password }}"
method: GET
validate_certs: false
status_code: 200
timeout: 30
  register: result

- name: debug
  ansible.builtin.debug:
var: result.json.data
// 

$ python3 --version
Python 3.6.8
$ ansible --version
ansible [core 2.13.3]
  config file = /users/admin/ansible.cfg
  configured module search path = ['/users/admin/.ansible/plugins/modules', 
'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = 
/users/admin/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.13 (main, Nov  9 2022, 13:16:24) [GCC 8.5.0 20210514 
(Red Hat 8.5.0-15)]
  jinja version = 3.1.2
  libyaml = True
$

// 

$ ansible-playbook uricall.yml -l reqres.in/api/users?page=2 -vvv
ansible-playbook [core 2.13.3]
  config file = /users/admin/ansible.cfg
  configured module search path = ['/users/admin/.ansible/plugins/modules', 
'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = 
/users/admin/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible-playbook
  python version = 3.9.13 (main, Nov  9 2022, 13:16:24) [GCC 8.5.0 20210514 
(Red Hat 8.5.0-15)]
  jinja version = 3.1.2
  libyaml = True
Using /users/admin/ansible.cfg as config file
host_list declined parsing /users/admin/hosts as it did not pass its 
verify_file() method
script declined parsing /users/admin/hosts as it did not pass its 
verify_file() method
auto declined parsing /users/admin/hosts as it did not pass its 
verify_file() method
Parsed /users/admin/hosts inventory source with ini plugin
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: uricall.yml 
*
1 plays in uricall.yml

PLAY [Validate KIE Server deployment] 
*
META: ran handlers

TASK [list details] 
***
task path: /users/admin/uricall.yml:15
 ESTABLISH SSH CONNECTION FOR USER: None
 SSH: EXEC ssh -C -o ControlMaster=auto -o 
ControlPersist=60s -o KbdInteractiveAuthentication=no -o 
PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey 
-o PasswordAuthentication=no -o ConnectTimeout=10 -o 
'ControlPath="/users/admin/.ansible/cp/2abdb2e15a"' 
reqres.in/api/users?page=2 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
 (0, b'/users/admin\n', b'')
 ESTABLISH SSH CONNECTION FOR USER: None
 SSH: EXEC ssh -C -o ControlMaster=auto -o 
ControlPersist=60s -o KbdInteractiveAuthentication=no -o 
PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey 
-o PasswordAuthentication=no -o ConnectTimeout=10 -o 
'ControlPath="/users/admin/.ansible/cp/2abdb2e15a"' 
reqres.in/api/users?page=2 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo 
/users/admin/.ansible/tmp `"&& mkdir "` echo 
/users/admin/.ansible/tmp/ansible-tmp-1676942607.0676842-2055362-84558986433951 
`" && echo ansible-tmp-1676942607.0676842-2055362-84558986433951="` echo 

[ansible-project] Re: need help in passing external variables using vars_prompt

2023-02-20 Thread Todd Lewis
Another solution is to use the "vars" lookup with your vars_prompt for 
"target" as you showed them above.

- name: Start a logical partition.
  powervm_lpar_instance:
hmc_host: "{{ lookup('vars',target).hmc }}"
hmc_auth: "{{ curr_hmc_auth }}"
system_name: "{{ lookup('vars',target).ms }}"
vm_name: "{{ target }}"
action: poweron

On Monday, February 20, 2023 at 12:29:45 PM UTC-5 Kenady Inampudi wrote:

> need help in passing external variables using vars_prompt
>
> working example i have a list of servers in a vars_file lparlist.yml
>
> i need to use vars_prompt so i can provide the server name without editing 
> the playbook every time
>
>
> working example
>
> *inventory*
> cat inventory
> [hmc]
> hmc1
> hmc2
>
>
> *vars_file*
> cat lparlist.yml
>
> ---
> - lpar1:
> hmc: hmc1
> ms: ms1
> - lpar2:
> hmc: hmc2
> ms: ms2
>
> *actual playbook:*
>
> ---
> - name: Start a logical partition
>   hosts: "{{ lpar1.hmc }}"
>   collections:
>   - ibm.power_hmc
>   connection: local
>   vars_files:
> - lparlist.yml
>   vars:
> curr_hmc_auth:
>   username: username
>   password: password
>   tasks:
> - name: Start a logical partition.
>   powervm_lpar_instance:
> hmc_host: "{{ lpar1.hmc }}"
> hmc_auth: "{{ curr_hmc_auth }}"
> system_name: "{{ lpar1.ms }}"
> vm_name: lpar1
> action: poweron
>
>
>
> *output*
>
> PLAY [Start a logical partition] 
> ***
>
> TASK [Gathering Facts] 
> 
> ok: [hmc1]
>
> TASK [Start a logical partition.] 
> **
> changed: [hmc1]
>
> PLAY RECAP 
> 
> hmc1   : ok=2changed=1unreachable=0failed=0   
>  skipped=0rescued=0ignored=0
>
>
>
> *not working playbook*
>
>
> ---
> - name: Start a logical partition
>   hosts: "{{ lpar1.hmc }}"
>   vars_prompt:
> - name: target
>   prompt: Enter Server Name
>   private: false
>   collections:
>   - ibm.power_hmc
>   connection: local
>   vars_files:
> - lparlist.yml
>   vars:
> curr_hmc_auth:
>   username: username
>   password: password
>   tasks:
> - name: Start a logical partition.
>   powervm_lpar_instance:
> hmc_host: "{{ target.hmc }}"
> hmc_auth: "{{ curr_hmc_auth }}"
> system_name: "{{ target.ms }}"
> vm_name: "{{ target }}"
> action: poweron
>
>
> *output*
>
> PLAY [Start a logical partition] 
> ***
>
> TASK [Gathering Facts] 
> 
> ok: [hmc1]
>
> TASK [Start a logical partition.] 
> **
> fatal: [hmc1]: FAILED! => {"msg": "The task includes an option with an 
> undefined variable. The error was: 'unicode object' has no attribute 
> 'ms'\n\nThe error appears to be in '/home/inampk48/hmc/p3/poweron.yml': 
> line 17, column 7, but may\nbe elsewhere in the file depending on the exact 
> syntax problem.\n\nThe offending line appears to be:"\n- name: Start a 
> logical partition.\n  ^ here\n"}
>
>
> PLAY RECAP 
> 
> hmc1   : ok=1changed=0unreachable=0failed=1   
>  skipped=0rescued=0ignored=0
>

-- 
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/b503c73c-cd11-4fb1-b8b3-b6f0e263ef98n%40googlegroups.com.


[ansible-project] Re: need help in passing external variables using vars_prompt

2023-02-20 Thread Todd Lewis
You're getting your "target" variable from vars_prompt just fine. It's a 
'unicode object' (i.e. a string), so you can't use its non-existent 'ms' 
attribute. If you really want to pull in the "target" host interactively, 
the easiest fix is to restructure your "lparlist.yml" file like this:

---
lpars:
  lpar1:
  hmc: hmc1
  ms: ms1
  lpar2:
  hmc: hmc2
  ms: ms2

Note: it's no longer a list, so "lparlist.yml" may not be a great name.
Then you use "target" (which would be either "lpar1" or "lpar2") like so:

- name: Start a logical partition.
  powervm_lpar_instance:
hmc_host: "{{ lpars[target].hmc }}"
hmc_auth: "{{ curr_hmc_auth }}"
system_name: "{{ lpars[target].ms }}"
vm_name: "{{ target }}"
action: poweron

But if you do it that way, you've inadvertently re-implements the "hosts:" 
functionality. Given your inventory, I think you should hard-code the group 
in hosts:

hosts: hmc

and drop "vars_prompt" and "target" altogether. Limit the hosts on the 
command line when necessary:

ansible-playbook playbookname.yml --limit=hmc1

Then your playbook becomes

- name: Start a logical partition.
  powervm_lpar_instance:
hmc_host: "{{ inventory_hostname }}" # either 'hmc1' or 'hmc2'
hmc_auth: "{{ curr_hmc_auth }}"
system_name: "{{ item.value.ms }}" # either 'ms1' or 'ms2'
vm_name: "{{ item.key }}"  # either 'lpar1' or 'lpar2'
action: poweron
  loop: "{{ lpars | dict2items }}"
  where: item.value.hmc == inventory_hostname



On Monday, February 20, 2023 at 12:29:45 PM UTC-5 Kenady Inampudi wrote:

> need help in passing external variables using vars_prompt
>
> working example i have a list of servers in a vars_file lparlist.yml
>
> i need to use vars_prompt so i can provide the server name without editing 
> the playbook every time
>
>
> working example
>
> *inventory*
> cat inventory
> [hmc]
> hmc1
> hmc2
>
>
> *vars_file*
> cat lparlist.yml
>
> ---
> - lpar1:
> hmc: hmc1
> ms: ms1
> - lpar2:
> hmc: hmc2
> ms: ms2
>
> *actual playbook:*
>
> ---
> - name: Start a logical partition
>   hosts: "{{ lpar1.hmc }}"
>   collections:
>   - ibm.power_hmc
>   connection: local
>   vars_files:
> - lparlist.yml
>   vars:
> curr_hmc_auth:
>   username: username
>   password: password
>   tasks:
> - name: Start a logical partition.
>   powervm_lpar_instance:
> hmc_host: "{{ lpar1.hmc }}"
> hmc_auth: "{{ curr_hmc_auth }}"
> system_name: "{{ lpar1.ms }}"
> vm_name: lpar1
> action: poweron
>
>
>
> *output*
>
> PLAY [Start a logical partition] 
> ***
>
> TASK [Gathering Facts] 
> 
> ok: [hmc1]
>
> TASK [Start a logical partition.] 
> **
> changed: [hmc1]
>
> PLAY RECAP 
> 
> hmc1   : ok=2changed=1unreachable=0failed=0   
>  skipped=0rescued=0ignored=0
>
>
>
> *not working playbook*
>
>
> ---
> - name: Start a logical partition
>   hosts: "{{ lpar1.hmc }}"
>   vars_prompt:
> - name: target
>   prompt: Enter Server Name
>   private: false
>   collections:
>   - ibm.power_hmc
>   connection: local
>   vars_files:
> - lparlist.yml
>   vars:
> curr_hmc_auth:
>   username: username
>   password: password
>   tasks:
> - name: Start a logical partition.
>   powervm_lpar_instance:
> hmc_host: "{{ target.hmc }}"
> hmc_auth: "{{ curr_hmc_auth }}"
> system_name: "{{ target.ms }}"
> vm_name: "{{ target }}"
> action: poweron
>
>
> *output*
>
> PLAY [Start a logical partition] 
> ***
>
> TASK [Gathering Facts] 
> 
> ok: [hmc1]
>
> TASK [Start a logical partition.] 
> **
> fatal: [hmc1]: 

[ansible-project] need help in passing external variables using vars_prompt

2023-02-20 Thread Kenady Inampudi
need help in passing external variables using vars_prompt

working example i have a list of servers in a vars_file lparlist.yml

i need to use vars_prompt so i can provide the server name without editing 
the playbook every time


working example

*inventory*
cat inventory
[hmc]
hmc1
hmc2


*vars_file*
cat lparlist.yml

---
- lpar1:
hmc: hmc1
ms: ms1
- lpar2:
hmc: hmc2
ms: ms2

*actual playbook:*

---
- name: Start a logical partition
  hosts: "{{ lpar1.hmc }}"
  collections:
  - ibm.power_hmc
  connection: local
  vars_files:
- lparlist.yml
  vars:
curr_hmc_auth:
  username: username
  password: password
  tasks:
- name: Start a logical partition.
  powervm_lpar_instance:
hmc_host: "{{ lpar1.hmc }}"
hmc_auth: "{{ curr_hmc_auth }}"
system_name: "{{ lpar1.ms }}"
vm_name: lpar1
action: poweron



*output*

PLAY [Start a logical partition] 
***

TASK [Gathering Facts] 

ok: [hmc1]

TASK [Start a logical partition.] 
**
changed: [hmc1]

PLAY RECAP 

hmc1   : ok=2changed=1unreachable=0failed=0   
 skipped=0rescued=0ignored=0



*not working playbook*


---
- name: Start a logical partition
  hosts: "{{ lpar1.hmc }}"
  vars_prompt:
- name: target
  prompt: Enter Server Name
  private: false
  collections:
  - ibm.power_hmc
  connection: local
  vars_files:
- lparlist.yml
  vars:
curr_hmc_auth:
  username: username
  password: password
  tasks:
- name: Start a logical partition.
  powervm_lpar_instance:
hmc_host: "{{ target.hmc }}"
hmc_auth: "{{ curr_hmc_auth }}"
system_name: "{{ target.ms }}"
vm_name: "{{ target }}"
action: poweron


*output*

PLAY [Start a logical partition] 
***

TASK [Gathering Facts] 

ok: [hmc1]

TASK [Start a logical partition.] 
**
fatal: [hmc1]: FAILED! => {"msg": "The task includes an option with an 
undefined variable. The error was: 'unicode object' has no attribute 
'ms'\n\nThe error appears to be in '/home/inampk48/hmc/p3/poweron.yml': 
line 17, column 7, but may\nbe elsewhere in the file depending on the exact 
syntax problem.\n\nThe offending line appears to be:"\n- name: Start a 
logical partition.\n  ^ here\n"}


PLAY RECAP 

hmc1   : ok=1changed=0unreachable=0failed=1   
 skipped=0rescued=0ignored=0

-- 
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/7bcebfbc-93df-4efa-858c-df9ed8f0be0cn%40googlegroups.com.


Re: [ansible-project] problem quoting string

2023-02-20 Thread Vladimir Botka
On Mon, 20 Feb 2023 07:03:54 -0800 (PST)
"gregory@gmail.com"  wrote:

> Hello, 
> 
> having something like this in my playbook
> vars:
>   somevar: 
>  command:
> - run: | 
> "somecommand 'somestring' | awk '{print $2}'"
> 
> tasks:
>- name: output var to file
>   copy:
>   content: "{{ somevar | to_nice_yaml(sort_keys=false,indent=2) }}"
>dest: /tmp/tempfile
>  
> when I look at /tmp/tempfile it looks like ansible doubles apostrophes:
> command:
>  -- run: '"somecommand ''somestring'' | awk ''{print $2}''"
> 
> is there any way to make ansible produce file without extra apostrophes?
> 
> thanks.
> 

Let's simplify the variable for testing

  cmd: |
"somecommand 'somestring'"


1) The filters *to_yaml* and *to_nice_yaml* will quote the strings

- copy:
dest: /tmp/tempfile
content: "{{ cmd|to_yaml }}"

gives (note the empty line and the closing single-quote

shell> cat /tmp/tempfile
'"somecommand ''somestring''"

  '

Remove the trailing new line by adding the dash to the block

  cmd: |-
"somecommand 'somestring'"

now the task creates the file

shell> cat /tmp/tempfile
'"somecommand ''somestring''"'

In a single-quoted block, the single-quote is the only character that
have to be escaped; by itself. This is the reason of the 'extra
apostrophes'.

2) Add the dash to your block to remove the new line

  somevar: 
 command:
   - run: |-
   "somecommand 'somestring' | awk '{print $2}'"

The filter *to_nice_yaml* will quote the string

- copy:
dest: /tmp/tempfile
content: "{{ somevar|to_nice_yaml }}"

gives valid YAML with the list *command* and single item

shell> cat /tmp/tempfile
command:
-   run: '"somecommand ''somestring'' | awk ''{print $2}''"'

Read the file and use the command

- include_vars:
 file: /tmp/tempfile
- command: "echo {{ command.0.run }}"
  register: out
- debug:
var: out.stdout

gives probably what you want

  out.stdout: somecommand 'somestring' | awk '{print $2}'

The run-string was properly expanded and used in the command line.

3) If you really want to get rid of the 'extra apostrophes' you'll
have to expand the strings in the template. For example,

- copy:
dest: /tmp/tempfile
content: |
  {% for key,val in somevar.items() %}
  {{ key }}:
  {% for i in val %}
  {% for k,v in i.items() %}
  - {{ k }}: {{ v }}
  {% endfor %}
  {% endfor %}
  {% endfor %}

gives

shell> cat /tmp/tempfile
command:
- run: "somecommand 'somestring' | awk '{print $2}'"

Note that now the double-quotes are not part of the string stored
in command.0.run


HTH,

-- 
Vladimir Botka

-- 
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/20230220175659.1b0cc62f%40gmail.com.


pgpyCI1jHAmyM.pgp
Description: OpenPGP digital signature


Re: [ansible-project] problem quoting string

2023-02-20 Thread Dick Visser
When I try that code I get something different altogether, note the
single dash for the list item:


 ~$ cat /tmp/tempfile
command:
- run: '"somecommand ''somestring'' | awk ''{print $2}''"

'

But this seems OK as that is what ansible is instructed to do.

So, the better question is what are you trying to do?
What do you want that file to look like - exactly?

Also, you ask for yaml, and when that is emitted, ansible (or the yaml
library) emits whatever is needed to make it valid YAML.


On Mon, 20 Feb 2023 at 16:04, gregory@gmail.com
 wrote:
>
> Hello,
>
> having something like this in my playbook
> vars:
>   somevar:
>  command:
> - run: |
> "somecommand 'somestring' | awk '{print $2}'"
>
> tasks:
>- name: output var to file
>   copy:
>   content: "{{ somevar | to_nice_yaml(sort_keys=false,indent=2) }}"
>dest: /tmp/tempfile
>
> when I look at /tmp/tempfile it looks like ansible doubles apostrophes:
> command:
>  -- run: '"somecommand ''somestring'' | awk ''{print $2}''"
>
> is there any way to make ansible produce file without extra apostrophes?
>
> 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/75403ea8-3d4d-4293-97cf-5ba77cfb1878n%40googlegroups.com.

-- 
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/CAF8BbLYvO5iHAsKqrOaX8iaN9sF67YTLkor3sYBrU%3D%3Ds7Xo_Qg%40mail.gmail.com.


[ansible-project] problem quoting string

2023-02-20 Thread gregory....@gmail.com
Hello, 

having something like this in my playbook
vars:
  somevar: 
 command:
- run: | 
"somecommand 'somestring' | awk '{print $2}'"

tasks:
   - name: output var to file
  copy:
  content: "{{ somevar | to_nice_yaml(sort_keys=false,indent=2) }}"
   dest: /tmp/tempfile
 
when I look at /tmp/tempfile it looks like ansible doubles apostrophes:
command:
 -- run: '"somecommand ''somestring'' | awk ''{print $2}''"

is there any way to make ansible produce file without extra apostrophes?

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/75403ea8-3d4d-4293-97cf-5ba77cfb1878n%40googlegroups.com.


[ansible-project] ansible-core autoupdate when installing awx version 21.5.0

2023-02-20 Thread Jerome Arellano
Hello,

i'm new to this group. I installed awx version 21.5.0 on RHEL release 8.6 
using awx release 0.28.0  and awx-operator release 0.28.0.
why the ansible-core is already updated to 2.14.2?  Is it bound to the 
python version of each respective RHEL release?
is it possible to downgrade the ansible-core version?

ansible [core 2.14.2]
  config file = None
  configured module search path = 
[/home/runner/.ansible/plugins/modules, 
/usr/share/ansible/plugins/modules]
  ansible python module location = 
/usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = 
/home/runner/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.16 (main, Dec  8 2022, 00:00:00) [GCC 11.3.1 
20221121 (Red Hat 11.3.1-4)] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

reason why i need the lower version of ansible-core is i'm managing RHEL6 
servers and the as mentioned in 
the https://access.redhat.com/articles/6977724 quote "RHEL 6 utilizes 
Python 2.6, and with the release of Ansible Core 2.13, managed nodes 
running Python 2.6 are no longer supported. Ansible Core 2.13 is planned to 
be included in RHEL 8.7 and 9.1."

thank you in advance.

-- 
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/4d1eb179-a4dc-4ffd-8fa4-dfa8fe1ff965n%40googlegroups.com.