The setup module

As we found out in Chapter 2, Installing and Running Ansible, the setup module gathers facts on our target host; if we call the module directly using the ansible command, the facts are printed directly on the screen. To call the module, we need to run the following command:

$ ansible windows -i production -m setup

As you can see from the following screen, the information displayed is pretty much identical to when we ran the module against a Linux host:

We can use one of the playbooks from Chapter 2Installing and Running Ansible, to see this. In playbook01.yml, we used the facts gathered by Ansible when it first connects to the hosts to display a message. Let's update that playbook to interact with our Windows host:

---

- hosts: windows
gather_facts: true

tasks:
- debug:
msg: "I am connecting to {{ ansible_nodename }} which is running {{ ansible_distribution }} {{ ansible_distribution_version }}"

As you can see, we have updated the host group to use windows rather than boxes, and we also removed the become and become_method options as the user we will be connecting with has enough permissions to run the tasks we need.

We can run the playbook using the following command:

$ ansible-playbook -i production playbook01.yml

The following screen gives the expected output:

Now we have quickly covered the basics, we can look at doing something useful and install a few different software packages.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.108.9