Re: [ansible-project] Async start a process and check until its listen port condition is successful

2022-06-21 Thread Mohtashim S
@Dick your solution takes 64 seconds for starting and checking for 
successful telnet if each of the three scripts has 30 seconds sleep time. 

With the below approach, it takes only half the time i.e 35 seconds to 
complete everything. 

cat main.yml

---

- name: Starting services
  gather_facts: false
  hosts: localhost
  tasks:

- include_tasks: "newinternal.yml"
  loop:
-  ~/startapp1.sh 4443
-  ~/startapp2.sh 4445
-  ~/startapp3.sh 4447

- name: Pause for 32 seconds to check telnet
  pause:
seconds: 32

- include_tasks: "waitnewinternal.yml"
  loop:
-  ~/startapp1.sh 4443
-  ~/startapp2.sh 4445
-  ~/startapp3.sh 4447

cat  newinternal.yml

   - shell: "{{ item.split()[0] }}"
 async: 600
 poll: 0

cat waitnewinternal.yml

   - name: Starting multiple wait_for tasks
 wait_for:
   host: localhost
   port: "{{ item.split()[1] }}"
   timeout: 43
 register: foo
 async: 600
 poll: 0
 changed_when: false

   - name: Collecting status of wait_for tasks
 async_status:
   jid: "{{ foo.ansible_job_id }}"
 register: jobs
 until: jobs.finished
 delay: 1
 retries: 600

Considering the solution you provided is async without bottlenecks I have 
the below 2 queries:

1. Can you please explain why the difference of half the time?
2. Can your solution be optimized so it also takes less than 40 seconds 
which makes sense. My solution is not ideal as the 32 seconds of sleep is 
not definitive and will vary from environment to environment. 

On Tuesday, June 21, 2022 at 12:42:29 AM UTC+5:30 dnmv...@gmail.com wrote:

> On Mon, 20 Jun 2022 at 21:06, Mohtashim S  wrote:
> >
> > @Dick under ` - name: Starting multiple wait_for tasks` -> i do not have 
> a loop ` loop: "{{ ports }}"` as my loop is in `main.yml` outer yml
> >
> > Thus, i get the following error:
> >
> > TASK [Collecting status of wait_for tasks] 
> *
> > task path: /root/newinternal.yml:17
> > fatal: [localhost]: FAILED! => {
> > "msg": "'dict object' has no attribute 'results'"
> > }
> >
> > Can you please suggest?
>
> I can't do everything for you.
> Look at the tasks/logic of the (fully working) playbook that I
> provided and adapt it to your situation.
>

-- 
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/5540f136-06de-4275-a941-5cd7e4dd7818n%40googlegroups.com.


[ansible-project] Re: Remove a line from file and surrounding

2022-06-21 Thread Laci
Thank you Jeff!
I ended up using a shell script with sed.

On Wednesday, June 15, 2022 at 1:37:01 PM UTC+2 Jeff S wrote:

> You can use those *modules, replace & lineinfile*, to search for a 
> pattern and replace it with something.
> ansible.builtin.replace module – Replace all instances of a particular 
> string in a file using a back-referenced regular expression — Ansible 
> Documentation 
> 
> ansible.builtin.lineinfile module – Manage lines in text files — Ansible 
> Documentation 
> 
> or use the *shell module* to work with sed!
>
> On Tuesday, June 14, 2022 at 4:59:38 PM UTC+2 Laci wrote:
>
>>
>> So far my best option is to run a command which invokes sed
>> On Tuesday, June 14, 2022 at 2:30:01 PM UTC+2 Laci wrote:
>>
>>> I'm working on a playbook which would remove lines from a file 
>>> containing specific hostname.
>>> I want to use Ansible to remove the hostname AND surrounding lines. Here 
>>> is an example of a block that I need to remove:
>>>
>>> FileSet {
>>> Name = "vcenter-hostname05"
>>>  Include {
>>>Options {
>>>signature = SHA1
>>>compression=GZIP
>>>noatime=yes
>>>  }
>>> Plugin = "vsphere: server=vsphere-vcenter host=hostname05.domain.com 
>>> abort_on_error"
>>>}
>>> }
>>>
>>> Does anyone have a suggestion how would I match the lines when all I 
>>> have is *hostname05*?
>>>
>>

-- 
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/d3a2933c-0a29-45cb-99ea-031369b5a037n%40googlegroups.com.


Re: [ansible-project] nested roles

2022-06-21 Thread Brian Coca
@Paul Mano the features @flowersong mentions are for installing, not
running the role. There has never been advice to use dependencies over
importing  a role. I have personally always advised the opposite, I
created import_role/include_role because the dependency mechanism is
very counterintuitive. I think you are mistaking the misuse of include
(used as current include_tasks) or include_vars targeting 'files from
a role' vs importing the role itself, this WAS advised against (still
is).

2.9 is EoL as is 2.10, the import_role/include_role features were added in 2.4.
-- 
--
Brian Coca

-- 
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/CACVha7fnHcLm%2BKGnv8bVO0WGBzkLc1KB6ZA4_FPFSYgb4%2Bx3kQ%40mail.gmail.com.


Re: [ansible-project] nested roles

2022-06-21 Thread Paul Manno
Hi Brian,

Wow... I could have swore I read that you should never import a role from 
another role: That is to say that in a role's tasks/main.yml to do 
import_role for some other role.  This made sense to me since a role, I 
thought, was supposed to only do one thing and do it well.  Importing one 
role from another would seem to inherently do more than one thing, and 
chaining roles like that could exhibit unpredictable behavior.  On the 
other hand having a playbook that chains import_role, of course, is fine 
and I get that.

So are you saying that importing a role from another role is an OK thing to 
do?

Paul
On Tuesday, June 21, 2022 at 9:39:45 AM UTC-5 Brian Coca wrote:

> @Paul Mano the features @flowersong mentions are for installing, not
> running the role. There has never been advice to use dependencies over
> importing a role. I have personally always advised the opposite, I
> created import_role/include_role because the dependency mechanism is
> very counterintuitive. I think you are mistaking the misuse of include
> (used as current include_tasks) or include_vars targeting 'files from
> a role' vs importing the role itself, this WAS advised against (still
> is).
>
> 2.9 is EoL as is 2.10, the import_role/include_role features were added in 
> 2.4.
> -- 
> --
> Brian Coca
>
>

-- 
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/998a0f48-e31a-42b9-81c8-83ea3cd66c27n%40googlegroups.com.


Re: [ansible-project] GCP inventory, inventory_hostname returning IP address

2022-06-21 Thread Brian Coca
Compose happens to late to set inventory_hostname, this is not a
'settable variable' but a variable that reflects the name with which
the host was added to inventory.

Being able to choose what to use as inventory_hostname  depends on the
inventory plugin,
many allow you to set inventory_hostname others do not.

In this case, the gcp_compute inventory plugin does allow it, and from
the docs it should work with 'name'

hostnames:
description: A list of options that describe the ordering for which
hostnames should be assigned. Currently supported hostnames are
'public_ip', 'private_ip', 'name' or 'labels.vm_name'.
default: ['public_ip', 'private_ip', 'name']

But docs can be wrong, so I looked at the code:
https://github.com/ansible-collections/google.cloud/blob/0cd64a4a68b7d4393c97b801e3f24e6b63882294/plugins/inventory/gcp_compute.py#L231,
this does seem to use the hostnames options/ordering to assign the
name. That code is then used to create the host
https://github.com/ansible-collections/google.cloud/blob/0cd64a4a68b7d4393c97b801e3f24e6b63882294/plugins/inventory/gcp_compute.py#L302
(which sets inventory_hostname to hostname()).

So the only thing I can think of .. the API is not returning 'name' as
part of the host information.
--
Brian Coca

-- 
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/CACVha7d9OFyinfaDPhQRLs3ZBSZ_jEA7KxVuYrvcS4ifHDrpYg%40mail.gmail.com.


Re: [ansible-project] ansible output not shown

2022-06-21 Thread Brian Coca
@High Racoon

The message is a bit misleading, it is not matching a host so it tries
to match a group (since hosts: allows for host patterns which can
include both), but then it sees the '-' and gives you the message
about invalid groups.

Note for @Todd Lewis
|ansible-config dump | grep -v default

no need for that, why you have --only-changed

ansible-config dump --only-changed



-- 
--
Brian Coca

-- 
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/CACVha7dXGnZr1B8vggHaR5znqzKpjfXxecpLSNK1GMXn4UaakA%40mail.gmail.com.


Re: [ansible-project] nested roles

2022-06-21 Thread Brian Coca
I prefer to keep things simple and obvious, I would keep role imports
to the play, not everyone agrees and many use complex role
hierarchies.

If it is a choice between setting 'dependencies' (which imports a role
from a role) and import_role, I always advise to use the latter.
reasons against dependencies:
- it is hidden in the 'meta' so it adds 'yet another file' to find out
the task flow
- they execute prior to the role with a lot of rules to which
variables and keywords are inherited
- the dependent is also the parent, which many find counterintuitive
- the import always happens, conditionals are appended to the
tasks/handlers on execution

with import/include:
- inheritance is clear, set at the time of import/inclusion (import
directly,  include via apply option)
- with include_role you can avoid importing at all, import_role
behaves closer to roles:/dependencies
- finer control on when to execute
- you can dynamically choose the role and/or entry points for the role
(tasks_from/vars_from/etc)

Currently the only advantage of dependency over include/import is that
it is both runtime and install time so you don't need to add the role
to 'requirements' file, which can be dealt with if we automate
requirements file creation (some issues with dynamic role selection,
but should work for static references).

--
Brian Coca

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


Re: [ansible-project] ansible output not shown

2022-06-21 Thread Todd Lewis
Thanks, Brian.
You've touched my love-hate-relationship-with-ansible nerve. It's an 
anti-feature that

   ansible-config --help dump

produces output different from

   ansible-config dump --help

the latter being the only way to discover "--only-changed".
And whether `man ansible-config` works depends on pip vs. system packaging.
Still, good to know about "--only-changed".

On Tuesday, June 21, 2022 at 10:58:33 AM UTC-4 Brian Coca wrote:

> Note for @Todd Lewis 
> |ansible-config dump | grep -v default 
>
> no need for that, why you have --only-changed 
>
> ansible-config dump --only-changed 
>
>
>
> -- 
> -- 
> Brian Coca 
>
>

-- 
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/9e5e3137-e3f2-4028-a233-082f510685aan%40googlegroups.com.


[ansible-project] How to put playbooks into a collection ?

2022-06-21 Thread Jan Goyvaerts
Hello Ansible Community,

I am in the process to develop my first collection. Among the requirements 
is including a number of playbooks. I can make everything work, except for 
playbooks. The ansible-playbook command can't find the playbooks. Nor can 
playbooks import them.

It happens even for the last Ansible release 5.9.0, so I must be doing 
something wrong in my collection. 

The directory structure:

*foo*
*+- sysadmin*

*+- playbooks*

*+- enable_ca.yml*

Deployment:

  ansible-galaxy collection build --force
  ansible-galaxy collection install foo-sysadmin-1.0.0.tar.gz --force

Running:

A playbook containing a playbook import:




*$ ansible-playbook test_playbook.yml ERROR! Unable to retrieve file 
contentsCould not find or access '/opt/.../foo.sysadmin.enable_ca.yml' on 
the Ansible Controller.If you are using a module and expect the file to 
exist on the remote, see the remote_src option*

Run it directly:


*$ ansible-playbook foo.sysadmin.enable_ca.ymlERROR! the playbook: 
foo.sysadmin.enable_ca.yml could not be found*

I was under the impression it was enough to put playbooks in 
.../foo/sysadmin/playbooks/.  

Or is it ?


-- 
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/d2d60326-06f0-43f1-a172-dd9c77f24ea0n%40googlegroups.com.


Re: [ansible-project] ansible output not shown

2022-06-21 Thread Brian Coca
I need to figure out how to use the argparser library to make those
more congruent.


-- 
--
Brian Coca

-- 
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/CACVha7eUWDEyHRURqcKNPddgOwRTHrm4CO1na2FGhcRZ-RYcgQ%40mail.gmail.com.


[ansible-project] Ansible 6.0.0 has been released!

2022-06-21 Thread Ompragash Viswanathan
Hi all,

We're happy to announce that *Ansible 6.0.0* package has been released!

Ansible 6.0.0 will include ansible-core 2.13 as well as a curated set of

Ansible collections to provide a vast number of modules and plugins.

This is a major version update from Ansible 5.x which included

ansible-core 2.12 and there may be backwards incompatibilities in the

core playbook language.

How to get it

-

This pre-release is available on PyPI and can be installed with pip:

```

$ pip install ansible==6.0.0 --user

```

The sources for this release can be found here:

Release tarball:

https://pypi.python.org/packages/source/a/ansible/ansible-6.0.0.tar.gz

SHA256: 641a2c27bc5768f9a8ad14880f1f6e571c1f2af1d45e76f271d76e3f74754c53

Wheel package:
https://files.pythonhosted.org/packages/py3/a/ansible/ansible-6.0.0-py3-none-any.whl


SHA256: 3a4516072660e34d4647db1627c401dffcbec23c50633d71ac7902e8c934e370

What's new in Ansible 6.0.0

---

* New command-line utility “ansible-community” is added in Ansible 6 to
check the installed version of Ansible Community package.

```

$ ansible-community --version

Ansible community version 6.0.0

```

* Python wheels are now available for both Ansible 6 and ansible-core

2.13.x, resulting in significantly improved installation performance.

* In addition, Ansible 6 will no longer install some unnecessary files

from the included Ansible collections such as tests or hidden files &

directories in order to further improve installation performance and

reduce the size on disk. These files are still available in the source

tarball if necessary.

* The changelog for ansible-core 2.13 installed by this release of

ansible is available here:

https://github.com/ansible/ansible/blob/stable-2.13/changelogs/CHANGELOG-v2.13.rst

* Collections which have opted into being a part of the Ansible-6

unified changelog will have an entry on this page:

https://github.com/ansible-community/ansible-build-data/blob/main/6/CHANGELOG-v6.rst

* For collections which have not opted into the unified changelog, you

may find more information on https://galaxy.ansible.com or their

source repository.

For example, the community.crypto collection would be found at

https://galaxy.ansible.com/community/crypto and you can find a link to

the source repository under the "Repo" button at the top right.

What's the schedule for new Ansible releases after 6.0.0 ?

-

* Maintenance releases of Ansible 6.x will occur approximately every

three weeks (Ansible 6.1.0, Ansible 6.2.0, etc) until the release of

Ansible 7.0.0. They will contain bugfixes and new features but no

backwards incompatibilities.

* Please note that the release of ansible-core 2.13 coincides with the
end-of-life of ansible 2.9 and ansible-base 2.10:

https://groups.google.com/g/ansible-announce/c/kegIH5_okmg/

Porting Help

-

A unified porting guide for collections which have opted-in is available
here:

https://docs.ansible.com/ansible/devel/porting_guides/porting_guide_6.html

Getting collection updates from Ansible 6 with older releases of
ansible-core

-

Ansible 6 includes ansible-core 2.13.x and users have expressed an interest

in getting collection updates as they ship in the Ansible "batteries

included" package while keeping an older version of ansible-core based

on their needs and requirements.

An ansible-galaxy requirements file based on the collections from

Ansible 6 has been made available for this use case:

https://github.com/ansible-community/ansible-build-data/blob/main/6/galaxy-requirements.yaml

Once the requirements file has been downloaded, the collections can be

installed by running:

"ansible-galaxy collection install -r galaxy-requirements.yaml"

On behalf of the Ansible community, thank you and happy automating !

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


Re: [ansible-project] nested roles

2022-06-21 Thread John Petro
@Brian Coca,
   So what you are suggesting, when you say you "prefer to keep things
simple and obvious" is that you suggest keeping the import statements in
the playbook that calls the role, not really inside the role itself, is
that what I am understanding you to mean by that?

--John

On Tue, Jun 21, 2022 at 11:45 AM Brian Coca  wrote:

> I prefer to keep things simple and obvious, I would keep role imports
> to the play, not everyone agrees and many use complex role
> hierarchies.
>
> If it is a choice between setting 'dependencies' (which imports a role
> from a role) and import_role, I always advise to use the latter.
> reasons against dependencies:
> - it is hidden in the 'meta' so it adds 'yet another file' to find out
> the task flow
> - they execute prior to the role with a lot of rules to which
> variables and keywords are inherited
> - the dependent is also the parent, which many find counterintuitive
> - the import always happens, conditionals are appended to the
> tasks/handlers on execution
>
> with import/include:
> - inheritance is clear, set at the time of import/inclusion (import
> directly,  include via apply option)
> - with include_role you can avoid importing at all, import_role
> behaves closer to roles:/dependencies
> - finer control on when to execute
> - you can dynamically choose the role and/or entry points for the role
> (tasks_from/vars_from/etc)
>
> Currently the only advantage of dependency over include/import is that
> it is both runtime and install time so you don't need to add the role
> to 'requirements' file, which can be dealt with if we automate
> requirements file creation (some issues with dynamic role selection,
> but should work for static references).
>
> --
> Brian Coca
>
> --
> 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/CACVha7cJWniX7iYMVN7SmPDdvim_wVDyWD9ppnjS_xnvMN%3D3fQ%40mail.gmail.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/CAPAjob9BGF9NiLszJRo0ojx0_maOgKaLx_2bs%2BT9UWGD%3DgLn5Q%40mail.gmail.com.


Re: [ansible-project] nested roles

2022-06-21 Thread Brian Coca
Yes, but that is not a commonly held view, why 'dependencies' exist,
so I suggest using import/include_role instead ... if i cannot
convince people of avoiding role 'trees'.


-- 
--
Brian Coca

-- 
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/CACVha7cqGgnT4qaz60m4AdT6zW977AyiAMBf9N3dLJ3K4v8_XQ%40mail.gmail.com.


Re: [ansible-project] nested roles

2022-06-21 Thread John Petro
That's really where I come down.  I'd rather see all dependancies in the
playbook, to avoid potential problems down the road.

On Tue, Jun 21, 2022, 6:13 PM Brian Coca  wrote:

> Yes, but that is not a commonly held view, why 'dependencies' exist,
> so I suggest using import/include_role instead ... if i cannot
> convince people of avoiding role 'trees'.
>
>
> --
> --
> Brian Coca
>
> --
> 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/CACVha7cqGgnT4qaz60m4AdT6zW977AyiAMBf9N3dLJ3K4v8_XQ%40mail.gmail.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/CAPAjob94QrGhOxfq35pis-mk49OHkHsr_iozrS_f7q6wicgP3g%40mail.gmail.com.


[ansible-project] How to send email if task fails on something or any particular condition? I

2022-06-21 Thread Milan Patel
---
- name: This playbook is for Testing Disk Space
  hosts: proxy
  become: yes
  become_method: sudo
  serial: 1
  any_errors_fatal: true
  ignore_errors: yes
  gather_facts: yes
  vars:
  ansible_paython_interpreter: /usr/bin/python
  tasks:

   - name: disk usage from command module
 shell: df -h / | tail -n 1 | awk '{ print $5 }'
 register: used_space

   - debug:
   var: used_space.stdout
 register: one

   - name: decision making weather to proceed with update the system or 
not
 fail: msg="{{ inventory_hostname }} have low disk space. Please 
Make some space then run the updates."
 when: used_space.stdout >= "70%"
 ignore_errors: no


   - name: update the system
 yum:
   name: "*"
   state: latest
   exclude: 'kernel*'
   update_cache: yes
   update_only: yes

 register: yum_update

   - debug:
   msg: "{{ yum_update }}"

**

In the example if disk space is used by 75% then task stops playing but in 
this case i want to set email notification send to me so how can i do that 
?? 

-- 
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/0f3253fb-90ff-4265-82cc-b85cc2b1c52dn%40googlegroups.com.