mbox series

[v3,0/4] ansible.cfg: generate with kconfig

Message ID 20250206-ansible_cfg3-v3-0-4588c8c07e22@samsung.com (mailing list archive)
Headers show
Series ansible.cfg: generate with kconfig | expand

Message

Daniel Gomez Feb. 6, 2025, 10:44 a.m. UTC
This series will generate the current in-tree ansible.cfg (Ansible
Configuration Settings) based on kconfig user options (kconfig menu
location: Kdevops configuration -> Ansible Configuration ->). Add
ansible.cfg Makefile target to manually generate the file, but also
append the target to the list of default make targets to make sure the
configuration file is generated.

The first commit just keeps the ansible.cfg as is. The second changes
the current settings to:

* Use dense [1] callback plugin instead of debug. This ensure a more
readable stdout convenient for normal operation. For CI, I recommend
setting AV=2 (Ansible Verbosity: -vv) or enable the debug plugin. For
error/debug user situations, or kdevops/Ansible development, re-run your
failed playbook with AV=1 or more.

Index of callback plugins can be found here:
https://docs.ansible.com/ansible/latest/collections/index_callback.html

Note: More updated settings below the examples.

Example running dense callback plugin with default Ansible verbosity
(AV=0 or nothing):

  make V=1 bringup
  ...
  ansible-playbook  --connection=local \
          --inventory localhost, \
          playbooks/gen_nodes.yml \
          -e 'ansible_python_interpreter=/usr/bin/python3' \
          --extra-vars=@./extra_vars.yaml
  PLAY 1: LOCALHOST
  task 1. [started TASK: Gathering Facts on localhost]
  task 2. [started TASK: gen_nodes : Import optional extra_args file on localhost]
  task 3. [started TASK: gen_nodes : Get our user on localhost]
  task 3: localhost
  task 4. [started TASK: gen_nodes : Get our primary group on localhost]
  task 4: localhost
  ...

Example running dense callback plugin with Ansible verbosity level
1 (AV=1):

  make V=1 AV=1 bringup
  ...
  ansible-playbook -v --connection=local \
          --inventory localhost, \
          playbooks/gen_nodes.yml \
          -e 'ansible_python_interpreter=/usr/bin/python3' \
          --extra-vars=@./extra_vars.yaml
  Using /media/tarkir/dagomez/src/linux-kdevops/kdevops/ansible.cfg as config file
  PLAY 1: LOCALHOST
  task 1. [started TASK: Gathering Facts on localhost]
  task 2. [started TASK: gen_nodes : Import optional extra_args file on localhost]
  task 3. [started TASK: gen_nodes : Get our user on localhost]
  task 3: gen_nodes : Get our user
  changed: localhost: {"changed": true, "cmd": ["whoami"], "rc": 0, "stdout": "dagomez"}
  task 4. [started TASK: gen_nodes : Get our primary group on localhost]
  task 4: gen_nodes : Get our primary group
  changed: localhost: {"changed": true, "cmd": ["id", "-g", "-n"], "rc": 0, "stdout": "dagomez"}
  ...

Example running dense callback plugin with default verbosity (AV=0),
error situation (error is "forced"/"simulated"):

  make V=1 bringup
  make linux-clone
  PLAY 1: LOCALHOST
  task 1. [started TASK: Gathering Facts on localhost]
  task 2. [started TASK: ansible_cfg : Import optional extra_args file on localhost]
  task 3. [started TASK: ansible_cfg : Generate kdevops ansible.cfg on localhost]
  
  ansible-playbook  --connection=local \
          --inventory localhost, \
          playbooks/gen_nodes.yml \
          -e 'ansible_python_interpreter=/usr/bin/python3' \
          --extra-vars=@./extra_vars.yaml
  PLAY 1: LOCALHOST
  task 1. [started TASK: Gathering Facts on localhost]
  task 2. [started TASK: gen_nodes : Import optional extra_args file on localhost]
  task 3. [started TASK: gen_nodes : Get our user on localhost]
  task 3: localhost
  task 4. [started TASK: gen_nodes : Get our primary group on localhost]
  task 4: localhost
  task 5. [started TASK: gen_nodes : Create guestfs directory on localhost]
  task 5: localhost
  
  make[1]: *** [Makefile:235: guestfs/kdevops_nodes.yaml] Error 2
  make: *** [scripts/guestfs.Makefile:55: 9p_linux_clone] Error 2

Example running dense callback plugin with verbosity level 1 (AV=1),
error situation (error is "forced"/"simulated"):

  make V=1 AV=1 bringup
  make linux-clone
  Using /media/tarkir/dagomez/src/linux-kdevops/kdevops/ansible.cfg as config file
  PLAY 1: LOCALHOST
  task 1. [started TASK: Gathering Facts on localhost]
  task 2. [started TASK: ansible_cfg : Import optional extra_args file on localhost]
  task 3. [started TASK: ansible_cfg : Generate kdevops ansible.cfg on localhost]
  SUMMARY
  localhost                  : ok=3    changed=0    unreachable=0    failed=0    rescued=0    ignored=0
  
  ansible-playbook -v --connection=local \
          --inventory localhost, \
          playbooks/gen_nodes.yml \
          -e 'ansible_python_interpreter=/usr/bin/python3' \
          --extra-vars=@./extra_vars.yaml
  Using /media/tarkir/dagomez/src/linux-kdevops/kdevops/ansible.cfg as config file
  PLAY 1: LOCALHOST
  task 1. [started TASK: Gathering Facts on localhost]
  task 2. [started TASK: gen_nodes : Import optional extra_args file on localhost]
  task 3. [started TASK: gen_nodes : Get our user on localhost]
  task 3: gen_nodes : Get our user
  changed: localhost: {"changed": true, "cmd": ["whoami"], "rc": 0, "stdout": "dagomez"}
  task 4. [started TASK: gen_nodes : Get our primary group on localhost]
  task 4: gen_nodes : Get our primary group
  changed: localhost: {"changed": true, "cmd": ["id", "-g", "-n"], "rc": 0, "stdout": "dagomez"}
  task 5. [started TASK: gen_nodes : Create guestfs directory on localhost]
  task 5: gen_nodes : Create guestfs directory
  failed: localhost: {"msg": "The task includes an
  option with an undefined variable.. 'guestfs_path_err'
  is undefined\n\nThe error appears to be in
  '/media/tarkir/dagomez/src/linux-kdevops/kdevops/playbooks/roles/gen_nod
  es/tasks/main.yml': line 21, column 3, but may\nbe elsewhere in the file
  depending on the exact syntax problem.\n\nThe offending line appears to
  be:\n\n\n- name: Create guestfs directory\n  ^ here\n"}
  SUMMARY
  localhost                  : ok=4    changed=2    unreachable=0    failed=1    rescued=0    ignored=0
  
  make[1]: *** [Makefile:235: guestfs/kdevops_nodes.yaml] Error 2
  make: *** [scripts/guestfs.Makefile:55: 9p_linux_clone] Error 2

* Enable show_per_host_start [3] parameter. This is a common parameter
between dense and debug callback plugins. Allows to know which task is
being executed rather than the current behaviour which only displays
terminated tasks.

* show_task_path_on_failure [4] parameter. Another commomn parameter
between dense and debug callback plugins. Allows to see the path and
file of the failure task when debug is -vv or greater.

[1] https://docs.ansible.com/ansible/latest/collections/community/general/dense_callback.html
[2] https://docs.ansible.com/ansible/latest/collections/ansible/posix/debug_callback.html#ansible-collections-ansible-posix-debug-callback
[3] https://docs.ansible.com/ansible/latest/collections/community/general/dense_callback.html#parameter-show_per_host_start
[4] https://docs.ansible.com/ansible/latest/collections/community/general/dense_callback.html#parameter-show_per_host_start

Signed-off-by: Daniel Gomez <da.gomez@samsung.com>
---
Changes in v3:
- Update patch trailers.
- Add support for Ansible callback plugin via cli
(ANSIBLE_CFG_CALLBACK_PLUGIN="<plugin_name>") as per Luis request.
- Update GitHub Actions to use the new ANSIBLE_CFG_CALLBACK_PLUGIN to
keep the same debug plugin instead of the new default (dense).
- Rename KDEVOPS_ANSIBLE_CFG_ to ANSIBLE_CFG_. Following Chuck's
request, it makes sense to further simplify the variables by removing
the redundant KDEVOPS_ prefix.
- Fix Ansible LSP/Lint warnings (true/false instead of True/False; Add
  FQCN to the ansible_cfg playbook/role and template tasks; set explicit
  template permissions).
- Cleanup ANSIBLE_CFG_CALLBACK_PLUGIN_<PLUGIN_NAME> from yaml output.
- Link to v2: https://lore.kernel.org/r/20250205-ansible_cfg3-v2-0-02620fc1e3d1@samsung.com

Changes in v2:
- Rename KDEVOPS_ANSIBLE_CONFIG_ -> KDEVOPS_ANSIBLE_CFG_ as per Chuck's
suggestion.
- Add kdevops_ansible_cfg_deprecation_warnings default value.
- Link to v1: https://lore.kernel.org/r/20250203-ansible_cfg3-v1-0-a9e75cd067d7@samsung.com
- Update base-commit to lastest upstream main.
- Update dependencies to "Fix debug mode" patches posted in the mailing
list. Add ansible_cfg to the ANSIBLE WRAPPER kdevops module.

---
Daniel Gomez (4):
      ansible.cfg: autogenerate using kconfig
      ansible.cfg: change defaults to minimal
      ansible_cfg: add callback plugin cli support
      github/workflows/fstests.yml: use debug callback plugin

 .github/workflows/fstests.yml                      |   1 +
 .gitignore                                         |   2 +
 MAINTAINERS                                        |   4 +
 Makefile                                           |  17 ++-
 ansible.cfg                                        |   5 -
 kconfigs/Kconfig.ansible_cfg                       | 123 +++++++++++++++++++++
 kconfigs/Kconfig.kdevops                           |   4 +
 playbooks/ansible_cfg.yml                          |   5 +
 playbooks/roles/ansible_cfg/defaults/main.yml      |  10 ++
 playbooks/roles/ansible_cfg/tasks/main.yml         |  18 +++
 .../roles/ansible_cfg/templates/ansible.cfg.j2     |  14 +++
 11 files changed, 194 insertions(+), 9 deletions(-)
---
base-commit: bcea53d0710cc0722520430277c80279e90e0863
change-id: 20250203-ansible_cfg3-3ad08ef2243b
prerequisite-change-id: 20250131-fix-dbg-fe4b275d90c7:v1
prerequisite-patch-id: dcbe4e784cf81c8863050d2829598e131b51a7ff
prerequisite-patch-id: 149905762e9801eb6da1872f6751cf430b9f0dda
prerequisite-patch-id: 8ea8b7694168bdae29156ab0c4696f0bac47815d

Best regards,