Setting Conditionals with Output

New at Ansible and still trying to get the hang of setting conditional based upon output.

I am setting Windows file shares with the below task. The initial run works fine; however, when you repeat the task, it fails stating that the shares already exist. How do I set a conditional that states if the network share already exists ignore, move on, rather than fail the run.

Task:

  • name: Set File Shares
    win_shell: |
    net share WebContent=“E:\Inetpub\wwwroot” /Grant:Everyone,READ /Grant:OSC\ServerAdministrator,CHANGE
    net share LogFiles=“F:\Inetpub\LogFiles” /Grant:Everyone,READ
    net share Indexes=“C:\Indexes” /Grant:Everyone,READ /Grant:OSC\ServerAdministrator,CHANGE
    net share Components=“C:\Component Services” /Grant:Everyone,READ /Grant:OSC\ServerAdministrator,CHANGE
    net share Resources=“C:\Inetpub” /Grant:Everyone,READ /Grant:OSC\ServerAdministrator,CHANGE

Output:

STDOUT:

LogFiles was shared successfully.

STDERR:

The name has already been shared.

More help is available by typing NET HELPMSG 2118.

The name has already been shared.

More help is available by typing NET HELPMSG 2118.

The name has already been shared.

More help is available by typing NET HELPMSG 2118.

The name has already been shared.

More help is available by typing NET HELPMSG 2118.

MSG:

non-zero return code

Hi,

Perhaps using the module which does this, you’ll have the idempotence :wink:

https://docs.ansible.com/ansible/latest/modules/win_share_module.html

Regars,

JYL

JYL,

Appreciate the recommendation. I should have mentioned that the Windows OS is 2008r2. I did try this module before submitting and per the win_share module docs and error message after run, this OS is not supported by the win_share module.

James