Ansible problem when i use --check

Hey !

I have problem when i use this command ansible-playbook playbook.yml --check

All works normaly without –check but when there is one task who create repertory, the second task is mistake.

Exemple :

  • name: “Create repertory”
    file:
    path: /var/apps/my_repertory
    state: directory

  • name: “Create file in my repertory”
    file:
    src: /home/wildfly/my_file
    dest: /var/apps/my_repertory/my_file

This tasks works perfectly without –check but when i use --check, the second task is mistake because ansible not really create my repertory …

Someone have any idea please community ansible ??!! =)

Thanks very much !! ^^

Regards,

Karther

Someone can help me please community ansible ??!!

Thanks very much !! :slight_smile:

Regards,

Yes, that is how it's supposed to work. The second task is dependent
on the first one, in this case only the first task can be used with
--check.
Getting a playbook to work properly with --check can be a tricky task,
you'll have to look at the logic in detail.
https://docs.ansible.com/ansible/latest/user_guide/playbooks_checkmode.html

Add the following to the second task at the end:

when: not ansible_check_mode

Hey !! :slight_smile:

Thanks very much for your answer community Ansible !! ^^

If i use this condiiton when: not ansible_check_mode i don’t can verify if my task works … :confused:

It’s very pity that aspect check mode is not full and strong… :frowning:

Thanks,

Regards,

Hi,

[...]
If i use this condiiton *when: not ansible_check_mode* i don't can verify
if my task works ... :confused:
It's very pity that aspect check mode is not full and strong... :frowning:

The option "--check" can be only as "full and strong" as is the support of
the modules. If you think you've found an aspect that is "very pity" just
open an issue with the module (ideally submit a pull-request).

Quoting from man ansible-playbook:

     -C, --check
        don't make any changes; instead, try to predict some of the changes
        that may occur

Cheers,

  -vlado