Hi everyone,

I apologise, I am new to Ansible and this is rather open ended.

After extensive use of the documentation I have my inventory, vars, vault 
and playbook all working together.  However, there is room for improvement.

This is my simple proof of concept playbook:
---
- name: Run powershell scripts.
  hosts: win

  tasks:

    - name: Remove SMB.
      # Removes an unsafe service, requires reboot.
      script: rm-SMB.ps1
      args:
        executable: powershell

    - name: Reboot if the reboot fact is true.
      win_reboot:
      when: "{{ ansible_facts['reboot_pending'] }}"

    - name: Rename Interface.
      # sets the network interface name.
      script: inter.ps1 -name bison
      args:
        executable: powershell

This works on an inventory of two Windows hosts, with usernames in vars and 
passwords in a vault.

The playbook runs as follows:
$ ansible-playbook rb-win.yml -i hosts.yml

PLAY [Run powershell scripts] *******************************************

TASK [Gathering Facts] 
*********************************************************
ok: [CM2]
ok: [CM1]

TASK [Remove SMB.] 
*************************************************************
changed: [CM2]
changed: [CM1]

TASK [Reboot if the reboot fact is true.] 
**************************************
 [WARNING]: conditional statements should not include jinja2 templating
delimiters such as {{ }} or {% %}. Found: {{ 
ansible_facts['reboot_pending'] }}

 [WARNING]: conditional statements should not include jinja2 templating
delimiters such as {{ }} or {% %}. Found: {{ 
ansible_facts['reboot_pending'] }}

skipping: [CM1]
changed: [CM2]

TASK [Rename Interface.] 
*******************************************************
changed: [CM1]
changed: [CM2]

PLAY RECAP 
*********************************************************************
CM1                        : ok=3    changed=2    unreachable=0    
failed=0    skipped=1    rescued=0    ignored=0
CM2                        : ok=4    changed=3    unreachable=0    
failed=0    skipped=0    rescued=0    ignored=0


Here are some questions:

The goal is to make the host reboot only if the ansible fact 
'reboot_pending' is true.  This is achieved but generates a warning, is 
there a better way of doing this?

It looks like the first and third tasks are run each time, is it possible 
skip these tasks if the playbook has been run before and the resources are 
already in the desired state?

Is it possible to pass arguments to the scripts separately to improve 
readability?

Any hints and tips or best practises would be greatly appreciated also!


--
Thank you.

Stephen.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/42205d48-cb2b-49da-a3bb-69dddb351c90%40googlegroups.com.

Reply via email to