UPDATE: Though this Q has been marked as a typo (and therefore "less useful to users"), the issue was actually needing to use the correct ansible module; shell
, rather than the command
module.
I'm hoping someone can show me where I'm going wrong here please, I'm guessing it's to do with the syntax or escaping or characters (though I've tried replacing awk (with its curlies) with cut, but no luck) in the command line which is causing the following error:
"stderr": "\u001b[1;31mE: \u001b[0mCommand line option 'F' [from -F,] is not understood in combination with the other options.\u001b[0m"
Basically in the role I've created, I want to dynamically store a list of whatever packages happen to be installed that are gnome or x11, then remove them using apt;
- name: Generate variable containing all gnome GUI packages
command: apt list | awk -F, '/gnome/ && /installed/ {print $1}'
register: gui_packages
ignore_errors: yes
changed_when: false
- name: Remove entire GUI
apt:
name:
- "{{ gui_packages_to_remove_specific }}"
- "{{ gui_packages }}"
state: absent
force: yes
when:
- remove_gui_packages is defined
- remove_gui_packages is true
Thanks in advance for any help you can give!!
From the documentation of the command
module:
The command(s) will not be processed through the shell, so variables like $HOSTNAME and operations like "*", "<", ">", "|", ";" and "&" will not work. Use the ansible.builtin.shell module if you need these features.
Your syntax problem is that you are not running apt
piped to awk
. You are running apt
and giving it all of list | awk -F, '/gnome/ && /installed/ {print $1}'
as arguments.