------------------------------------------------------------------------------- To run ansible... -vC # verbose (one level) and check mode (show result structure) -vD # With file differences -vv # more verbose (show location of task) -vvv # verbose including communication, and formatted result data --start-at-task=START # start processing playbook at this task --list-hosts # double check what hosts playbook runs against --list-tasks # what tasks are going to be attempted -l 'limit host glob' # ANSIBLE_LIMIT in ansible-runtime pipeline To make output more 'human readable' (default is "json") Add environment ANSIBLE_STDOUT_CALLBACK=debug # for ad-hoc tasks... ANSIBLE_LOAD_CALLBACK_PLUGINS=1 Or add to your ".ansible.cfg" [defaults] stdout_callback: debug # for ad-hoc tasks... bin_ansible_callbacks: True Other callback plugins... unixy more command line like tree asci tree style yaml readable but still less amount of spaces than 'debug' dense minimal Many output callbacks have extra configuration settings that can be used. For example, teh debug callback... https://docs.ansible.com/ansible/latest/collections/ansible/posix/debug_callback.html --- ansible-runtime pipeline... Push it up but don't run it (will still runs on a merge to production) git push -o ci.skip Set environment variables... git push -o ci.variable=ANSIBLE_FLAGS="--start-at-task=START -vvv" WARNING: gitlab CI breaks up any any variables with spaces, regardless of how you quote it. As such the task name can NOT have spaces in it. Arrgghh... Output style ANSIBLE_STDOUT_CALLBACK=debug Limit what hosts to run against (used by pipeline for dev/prd split) ANSIBLE_LIMIT='gc-dev-somehost.*' ANSIBLE_LIMIT='*-somehost.*' These are GLOBs, not RegRex. The '.' in the above MUST exist You can use glob patterns types: '?' '*' '[abc]' '[a-m]' You can NOT use a 'not' character range: '[^g]' which matches '^' and 'g' WARNING: If there are two or more pipelines in the gitlab CI, one will need to be manually terminated, or BOTH will try to run with the same hostlist! Set multiple environment variables (one each) git push \ -o ci.skip -o -o ci.variable=ANSIBLE_STDOUT_CALLBACK=debug \ -o ci.variable=ANSIBLE_VERBOSE=-vv \ -o ci.variable=ANSIBLE_LIMIT='dummy-*:na-prd-skeleton.*' # Running on legacy_ora -- even trickier ANSIBLE_LIMIT dummy-*:gc-prd-* ANSIBLE_LIMIT dummy-*:na-prd-* ANSIBLE_LIMIT dummy-*:app_dot_net_fusion_middleware_db_prd # There is no way to stop it doing a specific DEV host 5 times! # This has all changed in ansible-runtime # It may still work with # -o ci.variable=ANSIBLE_FLAGS=--start-at-task=START \ # -o ci.variable=ANSIBLE_FLAGS='--tag firewall' \ # -o ci.variable=ANSIBLE_FLAGS='--extra-vars skip_soe=true' \ # -o ci.variable=ANSIBLE_FLAGS='--extra-vars ansible_ssh_common_args=-vv' \ ------------------------------------------------------------------------------- Local Host Test "playbook.yml" =======8<-------- --- - name: Test Playbook hosts: all gather_facts: false tasks: - name: Test Task ansible.builtin.debug: msg: testing 1 2 3 =======8<-------- ansible-playbook --connection local -i localhost, playbook.yml NOTE: This will still call localhost using the ssh command (whatever is set) during the setup stage, though I don't know why it should do this, as connection is supposed to be 'local'. ------------------------------------------------------------------------------- Remote Host "playbook.yml" =======8<-------- --- - name: Test Playbook hosts: all remote_user: root tasks: - name: Test Task ansible.builtin.debug: msg: testing 1 2 3 =======8<-------- ansible-playbook -u root -i na-tst-ant, playbook.yml ------------------------------------------------------------------------------- Host Group "inventory.yml" =======8<-------- all: children: app_smtp_internal: hosts: smtp.example.com: =======8<-------- "project/main.yml" =======8<-------- --- - hosts: app_smtp_internal remote_user: ansible tasks: - command: whoami register: result - debug: var: result.stdout =======8<-------- # But we want to connect as "root", not "ansible" # and only to the specific hosts in given inventory ansible-playbook -e ansible_ssh_user=root -i inventory.yml project/main.yml =============================================================================== A "~ansible" directory bug... FYI, in case someone else runs across this! Had a very weird ansible error for a specific host... For some reason ansible created a "/home/ansible/~ansible" directory and was trying to use that directory to delete the tasks 'tmp' file and naturally failing. Ansible would just not proceed past this point. There does not appear to be anything special about the ansible rule for it either! Another machine, which should be exactly the same, did not have any such problems. So it is specific to the host itself and not the playbook. I don't know why it created the directory, and it even creates the directory, if it does not exist on each run! I removed that directory and replaced it with a symbolic link ln -s . ~ansible/~ansible so it points to the right location, and re-ran the pipe and all was OKAY. Directory exists, and points to right location. After this, removing the symbolic link was fine as ansible did not actually need to do anything for that specific rule (it is OK). But ansible still created the weird "~ansible" directory in the ansible home! I restored the symbolic link again, just in case it effects something else in future on this machine. Possibly related to https://github.com/ansible/ansible/issues/73683 -------------------------------------------------------------------------------