[ansible-project] Need to understand how I can write a ansible role so that it compares input / output value.

2021-12-20 Thread Marian Saldhana
Hi All,

As I am new to ansible i need to write a role which compares input /output 
value.

Let me elaborate.

I need to write a role where I already have expected value, for eg hostname 
of ansible remote node - abc.

Now I need to write a role which first will fetch the value from the remote 
node and then compare the fetched value with the expected value ( abc ) I 
have with me.

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/b708d4e2-ded7-44f0-b68a-866e93ec860bn%40googlegroups.com.


Re: [ansible-project] Execute an .sql script on mysql with secure installation

2021-12-20 Thread Antony Stone
On Monday 20 December 2021 at 18:08:23, Tiago Oliveira wrote:

> I am trying to use an sql script to create a database in mariadb on a
> openbsd server with ansible.
>
> My playbook first create the script with the name of the database to create
> and then uses expect to give the command "mysql -u root -p < script.sql"
> and then responses the password with "" because theres no password.

So, why don't you simply omit the "-p" to avoid being prompted for the non-
existent password?


Antony.

-- 
I conclude that there are two ways of constructing a software design: One way 
is to make it so simple that there are _obviously_ no deficiencies, and the 
other way is to make it so complicated that there are no _obvious_ 
deficiencies.

 - C A R Hoare

   Please reply to the list;
 please *don't* CC me.


Re: [ansible-project] Execute an .sql script on mysql with secure installation

2021-12-20 Thread Stefan Hornburg (Racke)

On 20/12/2021 18:42, Tiago Oliveira wrote:

oops, wrong code.

- name: Create a new .sql file for the table '{{table_name}}'
   template:
     src: templates/new_table_template
     dest: /home/secnet/{{table_name}}.sql

- name: Create the new database with name '{{table_name}}'
   expect:
     command: mysql -u root -p < {{table_name}}.sql
     responses:
       'Enter password:': ''
   register: wp
   failed_when: wp.rc not in [ 0, 1 ]

This one is the right one


From expect module documentation:

-- snip --
If you want to run a command through the shell (say you are using <, >, |, and so on), 
you must specify a shell in the command such as /bin/bash -c "/path/to/something | grep 
else".
-- snap --

Don't understand why you try to feed an empty password to MySQL. Do you use 
become: yes in your playbook? This would execute the task as root user.

Regards
  Racke



A segunda-feira, 20 de dezembro de 2021 à(s) 17:28:50 UTC, Tiago Oliveira 
escreveu:

Yeah, sorry.

- name: Create a new .sql file for the table '{{table_name}}'
   template:
     src: templates/new_table_template
     dest: /home/secnet/{{table_name}}.sql
   expect:
     command: mysql -u root -p < {{table_name}}.sql
     responses:
       'Enter password:': ''
   register: wp
   failed_when: wp.rc not in [ 0, 1 ]

The mysql_db module cant enter in mysql, returns the error     "msg": 
"unable to connect to database, check login_user and login_password are correct or 
/root/.my.cnf has
the credentials. Exception message: (1698, \"Access denied for user 
'root'@'localhost'\")"
}

since i need to enter with root user.

  Regards,

Tiago
A segunda-feira, 20 de dezembro de 2021 à(s) 17:14:36 UTC, ra...@linuxia.de 
escreveu:

On 20/12/2021 18:08, Tiago Oliveira wrote:
 > Hi,
 > I am trying to use an sql script to create a database in mariadb on 
a openbsd server with ansible.
 > My playbook first create the script with the name of the database to create and then uses 
expect to give the command "mysql -u root -p < script.sql" and then responses the password 
with "" because theres no password.
 > I try to use the script created by ansible and it works.
 > I try to use the same command that ansible is using and it works.
 > I took the "< script.sql" part to see if the problem was the 
password, and ansible enter in mysql without returning any error.
 >
 > When i use the playbook with "< script.sql" in command, ansible 
returns the error of non-zero return code returning rc=1.
 >
 > Anyone know how to solve it??

Maybe you start with sharing your playbook and the contents of the 
script!?

The modules mysql_user and mysql_db should be able to create your 
database with the associated users.

Regards
Racke

 >
 > I've tried also the community.mysql module, but it didnt worked also 
to create the first database.
 >
 > Best Regards,
 >
 > Tiago Oliveira
 >
 > --
 > 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-proje...@googlegroups.com 
.
 > To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/44af35a2-29db-4847-a9fe-a1f27a0dc1ebn%40googlegroups.com 

 
>.


-- 
Ecommerce and Linux consulting + Perl and web application programming.

Debian and Sympa administration.


--
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/8e92a586-abe3-493d-8506-563a82801b1cn%40googlegroups.com
 
.



--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration.


--
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 

Re: [ansible-project] Execute an .sql script on mysql with secure installation

2021-12-20 Thread Tiago Oliveira
oops, wrong code.

- name: Create a new .sql file for the table '{{table_name}}'
  template:
src: templates/new_table_template
dest: /home/secnet/{{table_name}}.sql

- name: Create the new database with name '{{table_name}}'
  expect: 
command: mysql -u root -p < {{table_name}}.sql
responses:
  'Enter password:': ''
  register: wp
  failed_when: wp.rc not in [ 0, 1 ]

This one is the right one

A segunda-feira, 20 de dezembro de 2021 à(s) 17:28:50 UTC, Tiago Oliveira 
escreveu:

> Yeah, sorry.
>
> - name: Create a new .sql file for the table '{{table_name}}'
>   template:
> src: templates/new_table_template
> dest: /home/secnet/{{table_name}}.sql
>   expect: 
> command: mysql -u root -p < {{table_name}}.sql
> responses:
>   'Enter password:': ''
>   register: wp
>   failed_when: wp.rc not in [ 0, 1 ]
>
> The mysql_db module cant enter in mysql, returns the error "msg": 
> "unable to connect to database, check login_user and login_password are 
> correct or /root/.my.cnf has 
> the credentials. Exception message: (1698, \"Access denied for user 
> 'root'@'localhost'\")"  
> } 
>   
>
> since i need to enter with root user.
>
>  Regards,
>
> Tiago
> A segunda-feira, 20 de dezembro de 2021 à(s) 17:14:36 UTC, 
> ra...@linuxia.de escreveu:
>
>> On 20/12/2021 18:08, Tiago Oliveira wrote: 
>> > Hi, 
>> > I am trying to use an sql script to create a database in mariadb on a 
>> openbsd server with ansible. 
>> > My playbook first create the script with the name of the database to 
>> create and then uses expect to give the command "mysql -u root -p < 
>> script.sql" and then responses the password with "" because theres no 
>> password. 
>> > I try to use the script created by ansible and it works. 
>> > I try to use the same command that ansible is using and it works. 
>> > I took the "< script.sql" part to see if the problem was the password, 
>> and ansible enter in mysql without returning any error. 
>> > 
>> > When i use the playbook with "< script.sql" in command, ansible returns 
>> the error of non-zero return code returning rc=1. 
>> > 
>> > Anyone know how to solve it?? 
>>
>> Maybe you start with sharing your playbook and the contents of the 
>> script!? 
>>
>> The modules mysql_user and mysql_db should be able to create your 
>> database with the associated users. 
>>
>> Regards 
>> Racke 
>>
>> > 
>> > I've tried also the community.mysql module, but it didnt worked also to 
>> create the first database. 
>> > 
>> > Best Regards, 
>> > 
>> > Tiago Oliveira 
>> > 
>> > -- 
>> > 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-proje...@googlegroups.com > ansible-proje...@googlegroups.com>. 
>> > To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/44af35a2-29db-4847-a9fe-a1f27a0dc1ebn%40googlegroups.com
>>  
>> <
>> https://groups.google.com/d/msgid/ansible-project/44af35a2-29db-4847-a9fe-a1f27a0dc1ebn%40googlegroups.com?utm_medium=email_source=footer>.
>>  
>>
>>
>>
>> -- 
>> Ecommerce and Linux consulting + Perl and web application programming. 
>> Debian and Sympa administration. 
>>
>>
>>

-- 
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/8e92a586-abe3-493d-8506-563a82801b1cn%40googlegroups.com.


Re: [ansible-project] Execute an .sql script on mysql with secure installation

2021-12-20 Thread Stefan Hornburg (Racke)

On 20/12/2021 18:08, Tiago Oliveira wrote:

Hi,
I am trying to use an sql script to create a database in mariadb on a openbsd 
server with ansible.
My playbook first create the script with the name of the database to create and then uses expect to 
give the command "mysql -u root -p < script.sql" and then responses the password with 
"" because theres no password.
I try to use the script created by ansible and it works.
I try to use the same command that ansible is using and it works.
I took the "< script.sql" part to see if the problem was the password, and 
ansible enter in mysql without returning any error.

When i use the playbook with "< script.sql" in command, ansible returns the 
error of non-zero return code returning rc=1.

Anyone know how to solve it??


Maybe you start with sharing your playbook and the contents of the script!?

The modules mysql_user and mysql_db should be able to create your database with 
the associated users.

Regards
Racke



I've tried also the community.mysql module, but it didnt worked also to create 
the first database.

Best Regards,

Tiago Oliveira

--
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/44af35a2-29db-4847-a9fe-a1f27a0dc1ebn%40googlegroups.com
 
.



--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration.


--
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/365a5e70-e323-2f9c-263d-58a0c5c616e3%40linuxia.de.


OpenPGP_signature
Description: OpenPGP digital signature


[ansible-project] Execute an .sql script on mysql with secure installation

2021-12-20 Thread Tiago Oliveira
Hi,
I am trying to use an sql script to create a database in mariadb on a 
openbsd server with ansible. 
My playbook first create the script with the name of the database to create 
and then uses expect to give the command "mysql -u root -p < script.sql" 
and then responses the password with "" because theres no password.
I try to use the script created by ansible and it works.
I try to use the same command that ansible is using and it works.
I took the "< script.sql" part to see if the problem was the password, and 
ansible enter in mysql without returning any error.

When i use the playbook with "< script.sql" in command, ansible returns the 
error of non-zero return code returning rc=1.

Anyone know how to solve it??

I've tried also the community.mysql module, but it didnt worked also to 
create the first database.

Best Regards,

Tiago Oliveira

-- 
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/44af35a2-29db-4847-a9fe-a1f27a0dc1ebn%40googlegroups.com.


[ansible-project] Re: create multiple vlan port groups on 5 esxi servers

2021-12-20 Thread Tony Wong
any idea?

On Sunday, December 19, 2021 at 1:12:36 PM UTC-8 Tony Wong wrote:

> i got following task to create mul;tiple vlan ports groups on a vswitch on 
> 5 esxi hosts
>
> task playbok is
>
> ---
> - name: create_vss_vlan_PGs
>   vmware_portgroup:
> hostname: '{{ vcenter_hostname }}'
> username: '{{ vcenter_username }}'
> password: '{{ vcenter_password }}'
> cluster_name: '{{ cluster_name }}'
> switch_name: '{{ vswitch_name }}'
> portgroup_name: '{{ portgroup_name }}'
> vlan_id: '{{ vlan_id }}'
>   delegate_to: localhost
>
>
> i have answer file like so
>
>
> vcenter_hostname: "myvcenter.domain.com"
> vcenter_username: "admini...@vsphere.local"
> vcenter_password: ""
> cluster_name: "cluster"
> switch_name: "vSwitch0"
> portgroup_name: "??"
> vlan_id: "?"
>
>
> my hosts file is
>
> [esx]
> esx1
> esx2
> esx3
> esx4
> esx5
>
> [esx:vars]
>
>
> any idea how i would create the portgroups with different vlan ids? which 
> file would i put them in?
>
>
>

-- 
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/46ed0fa4-76f6-4a52-89e3-cb39d9e79275n%40googlegroups.com.


[ansible-project] Check for existing installed software

2021-12-20 Thread Nitrous


How can I incorporate this registry check before my playbook runs to 
install .net 4.8:

(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\NET Framework 
Setup\NDP\v4\Full").version -lt 4.8

The above should only run my playbook, if 4.8 isnt installed. If version is 
less than 4.8 run the below playbook, else skip

My playbook to install .net 4.8:
- name: Copy .net 4.8 Files
  ansible.windows.win_copy:
src: /etc/ansible/roles/net481/files/ndp48-x86-x64-allos-enu.exe
dest: C:\Scripts\
state: present

- name: Install .net 4.8
  ansible.builtin.script: /etc/ansible/roles/onprembaseline/files/net48.ps1
  register: script_run

- name: Reboot after .NET 4.8 Install
  ansible.windows.win_reboot:

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/394d3f6d-13dc-42ab-9c18-cd923643125an%40googlegroups.com.


Re: [⚠️] Re: [ansible-project] Facing Issue Ansible Summary

2021-12-20 Thread Stefan Hornburg (Racke)

On 20/12/2021 15:44, 'Jitender J' via Ansible Project wrote:

Hi Antony,

Thanks for the mail, below is the playbook code snippet

##
- hosts: "{{ UI }}"
   gather_facts: no
   user: ops
   tasks:
    - name: Check total CPU cores
      shell: |
        cpu=`sysctl hw.model hw.machine hw.ncpu|grep  hw.ncpu:`
        echo "$cpu"|awk -F':' '{
        if ($2 >= 5)
         print "\033[32mOK:\033[0m" $0;
        else
         print $0,  echo -e "\033[31m CRITICAL\033[0m" }'
      register: err_cpu
      failed_when: '"CRITICAL" in err_cpu.stdout'
      args:
       executable: /bin/bash
      ignore_errors: true

    - name: Check total memory
      shell: |
        mem=`echo "$(sysctl -n hw.physmem)/1024/1024/1024"|bc`
        echo "$mem"|awk '{
        if ($NF >= 48)
         print "\033[32mOK:\033[0m" $0
        else
          print  $0,  echo -e "\033[31m CRITICAL\033[0m" }'
      register: err_mem
      failed_when: '"CRITICAL" in err_mem.stdout'
      args:
       executable: /bin/bash
      ignore_errors: true
#


Why don't use ansible_facts instead of these horrible shell hacks?

Regards
Racke



On Mon, Dec 20, 2021 at 8:06 PM Antony Stone mailto:antony.st...@ansible.open.source.it>> wrote:

On Monday 20 December 2021 at 15:34:02, 'Jitender J' via Ansible Project
wrote:

 > Hi Team,
 >
 > Facing a very strange issue, my failed task output getting swapped with
 > another task, in summary, we have done some modification in the callback
 > module but never saw like this before, any suggestion

My suggestion is to show us your playbook which can do this.

Antony.

-- 
What do you call a dinosaur with only one eye?  A Doyouthinkesaurus.


                                                    Please reply to the 
list;
                                                          please *don't* CC 
me.



--
*Regards,
*
*Jitender*

--
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/CAMO4JZs_XPhYKoHNqmjTYzLVWzCo%3Dr2v4o9VWYAomquz5nNXsA%40mail.gmail.com
 
.



--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration.


--
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/eab28ae1-9394-e273-1e36-b8079523ef1e%40linuxia.de.


OpenPGP_signature
Description: OpenPGP digital signature


Re: [⚠️] Re: [ansible-project] Facing Issue Ansible Summary

2021-12-20 Thread 'Jitender J' via Ansible Project
Hi Antony,

Thanks for the mail, below is the playbook code snippet

##
- hosts: "{{ UI }}"
  gather_facts: no
  user: ops
  tasks:
   - name: Check total CPU cores
 shell: |
   cpu=`sysctl hw.model hw.machine hw.ncpu|grep  hw.ncpu:`
   echo "$cpu"|awk -F':' '{
   if ($2 >= 5)
print "\033[32mOK:\033[0m" $0;
   else
print $0,  echo -e "\033[31m CRITICAL\033[0m" }'
 register: err_cpu
 failed_when: '"CRITICAL" in err_cpu.stdout'
 args:
  executable: /bin/bash
 ignore_errors: true

   - name: Check total memory
 shell: |
   mem=`echo "$(sysctl -n hw.physmem)/1024/1024/1024"|bc`
   echo "$mem"|awk '{
   if ($NF >= 48)
print "\033[32mOK:\033[0m" $0
   else
 print  $0,  echo -e "\033[31m CRITICAL\033[0m" }'
 register: err_mem
 failed_when: '"CRITICAL" in err_mem.stdout'
 args:
  executable: /bin/bash
 ignore_errors: true
#

On Mon, Dec 20, 2021 at 8:06 PM Antony Stone <
antony.st...@ansible.open.source.it> wrote:

> On Monday 20 December 2021 at 15:34:02, 'Jitender J' via Ansible Project
> wrote:
>
> > Hi Team,
> >
> > Facing a very strange issue, my failed task output getting swapped with
> > another task, in summary, we have done some modification in the callback
> > module but never saw like this before, any suggestion
>
> My suggestion is to show us your playbook which can do this.
>
> Antony.
>
> --
> What do you call a dinosaur with only one eye?  A Doyouthinkesaurus.
>
>Please reply to the
> list;
>  please *don't* CC
> me.
>


-- 

*Regards,*
*Jitender*

-- 
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/CAMO4JZs_XPhYKoHNqmjTYzLVWzCo%3Dr2v4o9VWYAomquz5nNXsA%40mail.gmail.com.


Re: [ansible-project] Facing Issue Ansible Summary

2021-12-20 Thread Antony Stone
On Monday 20 December 2021 at 15:34:02, 'Jitender J' via Ansible Project 
wrote:

> Hi Team,
> 
> Facing a very strange issue, my failed task output getting swapped with
> another task, in summary, we have done some modification in the callback
> module but never saw like this before, any suggestion

My suggestion is to show us your playbook which can do this.

Antony.

-- 
What do you call a dinosaur with only one eye?  A Doyouthinkesaurus.

   Please reply to the list;
 please *don't* CC me.


[ansible-project] Facing Issue Ansible Summary

2021-12-20 Thread 'Jitender J' via Ansible Project
Hi Team, 

Facing a very strange issue, my failed task output getting swapped with 
another task, in summary, we have done some modification in the callback 
module but never saw like this before, any suggestion 

[image: tt.PNG]

-- 
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/0cb38f3b-ba83-4b07-96b7-19fc3a348adbn%40googlegroups.com.


[ansible-project] Re: Prevent single failure killing playbook

2021-12-20 Thread Thomas Zarowski
Hi Omar,

Thanks for the suggestion - I tried this and was unable to get it to work. 
It seems correct if the value of serial is more than one, as it operates on 
a "per-batch" level as opposed to a "per-machine" level.

Thanks,
Tom

On Wednesday, December 15, 2021 at 11:11:48 PM UTC Omar wrote:

> Hi,
>
> I haven't tried it my self but I think max_fail_percentage 
> 
>  
> is what you are looking for.
>
>
> On Tuesday, December 14, 2021 at 7:47:50 PM UTC+3 thomasz...@gmail.com 
> wrote:
>
>> Hi All,
>>
>> I am currently running a playbook of several tasks, with serial:1 
>> specified.
>> If any of the tasks fail on host 1, I would like to still try them on 
>> host 2 and host 3 etc. Perhaps host 1 is just too busy at the time to 
>> execute the tasks, it seems annoying to have the whole playbook fail, 
>> particularly if running it overnight.
>>
>> It feels there should be a way to accomplish this, any ideas?
>>
>> Thanks,
>> Tom
>>
>

-- 
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/cf94649c-ac68-4a3e-b068-c7940959cc5dn%40googlegroups.com.