Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module debug to assist users in understanding Ansible #1213

Merged
merged 1 commit into from Oct 4, 2012

Conversation

dagwieers
Copy link
Contributor

After helping someone on IRC he was interested to have this debug module in upstream. This module simply 'prints' a message, and can be ordered to fail if needed. It helps to troubleshoot or understand inventory/facts issues and/or experiment with statements and conditions using only_if.

Here is a small example playbook:

- hosts: all
  tasks:
  - local_action: debug msg="System ${inventory_hostname} has ${ansible_eth0.ipv4.address}"
  - local_action: debug msg="System ${inventory_hostname} lacks a gateway" fail=yes
    only_if: "is_unset('$network_gateway')"
  - local_action: debug msg="System ${inventory_hostname} has gateway ${network_gateway}"
    only_if: "is_set('$network_gateway')"

outputting:

[root@moria ansible]# ansible-playbook -v -l localhost:x220 test6.yml

PLAY [all] *********************

GATHERING FACTS *********************
ok: [localhost]
ok: [x220]

TASK: [debug msg="System ${inventory_hostname} has ${ansible_eth0.ipv4.address}"] *********************
ok: [localhost] => {"msg": "System localhost has 10.1.2.127"}
ok: [x220] => {"msg": "System x220 has 192.168.1.214"}

TASK: [debug msg="System ${inventory_hostname} lacks a gateway" fail=yes] *********************
failed: [localhost] => {"failed": true, "msg": "System localhost lacks a gateway", "rc": 1}
ok: [x220] => {"msg": "System x220 has gateway 192.168.1.1"}

PLAY RECAP *********************
localhost                      : ok=2    changed=0    unreachable=0    failed=1
x220                           : ok=3    changed=0    unreachable=0    failed=0

I had some other plans for the module, like displaying host inventory and complete inventory to help understand inventory and facts modules, but that would require an action-plugin for transfering inventory information etc... And I am not sure this is wanted/best done in a module.

@broferek
Copy link

broferek commented Oct 3, 2012

Why the variables are not interpreted in the TASK result output ?
I'm trying to print variables as well in the name of the task but I do have the same issue.
TASK: [debug msg="System ${inventory_hostname} has ${ansible_eth0.ipv4.address}"]

BTW, this module will be very useful !!

@mpdehaan
Copy link
Contributor

mpdehaan commented Oct 3, 2012

Because the vars can be host specific

-- Michael

On Oct 3, 2012, at 9:53 AM, broferek notifications@github.com wrote:

Why the variables are not interpreted in the TASK result output ?
I'm trying to print variables as well in the name of the task but I do have the same issue.
TASK: [debug msg="System ${inventory_hostname} has ${ansible_eth0.ipv4.address}"]

BTW, this module will be very useful !!


Reply to this email directly or view it on GitHub.

@mpdehaan
Copy link
Contributor

mpdehaan commented Oct 4, 2012

Looks good. To avoid waves of user questions, please update the docs to mention this really should be run in verbose mode if you want to see the variables set for each host.

@ghost ghost assigned dagwieers Oct 4, 2012
After helping someone on IRC he was interested to have this debug module in upstream. This module simply 'prints' a message, and can be ordered to fail if needed. It helps to troubleshoot or understand inventory/facts issues and/or experiment with statements and conditions using only_if.

Here is a small example playbook:

```yaml
- hosts: all
  tasks:
  - local_action: debug msg="System $inventory_hostname has uuid ${ansible_product_uuid}"
  - local_action: debug msg="System $inventory_hostname lacks a gateway" fail=yes
    only_if: "is_unset('$ansible_default_ipv4.gateway')"
  - local_action: debug msg="System $inventory_hostname has gateway ${ansible_default_ipv4.gateway}"
    only_if: "is_set('$ansible_default_ipv4.gateway')"
```

outputting:
```
[root@moria ansible]# ansible-playbook -v -l localhost:x220 test6.yml

PLAY [all] *********************

GATHERING FACTS *********************
ok: [localhost]
ok: [x220]

TASK: [debug msg="System $inventory_hostname has uuid $ansible_product_uuid"] *********************
ok: [localhost] => {"msg": "System localhost has uuid d125a48c-364f-4e65-b225-fed42ed61fac"}
ok: [x220] => {"msg": "System x220 has uuid d125a48c-364f-4e65-b225-fed42ed61fac"}

TASK: [debug msg="System $inventory_hostname lacks a gateway" fail=yes] *********************
failed: [localhost] => {"failed": true, "msg": "System localhost lacks a gateway", "rc": 1}
ok: [x220] => {"msg": "System x220 has gateway 192.168.1.1"}

PLAY RECAP *********************
localhost                      : ok=2    changed=0    unreachable=0    failed=1
x220                           : ok=3    changed=0    unreachable=0    failed=0

```

I had some other plans for the module, like displaying host inventory and complete inventory to help understand inventory and facts modules, but that would require an action-plugin for transfering inventory information etc... And I am not sure this is wanted/best done in a module.
@dagwieers
Copy link
Contributor Author

As you wish !

mpdehaan added a commit that referenced this pull request Oct 4, 2012
Module debug to assist users in understanding Ansible
@mpdehaan mpdehaan merged commit f470ebe into ansible:devel Oct 4, 2012
@mpdehaan
Copy link
Contributor

mpdehaan commented Oct 4, 2012

merged, thanks!

@ansible ansible locked and limited conversation to collaborators Apr 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants