官术网_书友最值得收藏!

Executing Ansible

We have so far seen the installation of Ansible, listed the hosts in the inventory, and set up our Ansible playbook; now, we can run Ansible to configure our VMs.

For this, we will run the Ansible tool with the ansible-playbook command, like this:

ansible-playbook -i inventory playbook.yml

The basic options of this command are as follows:

  • The -i argument with the inventory file path 
  • The path of the playbook file

The following is the execution of this command:

The execution of this command applies the playbook to the hosts in the inventory in several steps:

  1. Gathering facts: Ansible checks that the hosts are reachable.
  2. The tasks' playbook is executed on hosts.
  3. PLAY Recap: This is the status of the changes that were executed on each host; the value of this status can be as follows:

 

If we need to upgrade our playbook to add or modify middleware on our VMs, during the second execution of Ansible with this upgraded playbook, it can be noticed that Ansible did not reapply the complete configuration of the VMs, but only applied the differences. 

The following screenshot shows the second execution of Ansible with no changes made to our playbook:

We can see in the recap step that Ansible didn't change anything on the hosts (changed=0).

We can also add some useful options to this command to provide the following:

  • A preview of Ansible changes before applying the changes
  • More logs in the execution output

These options are not only important for the playbook development phase, but also for debugging them in case of errors during their execution.

Now, let's look at how to use these preview options.

主站蜘蛛池模板: 会昌县| 道孚县| 乳山市| 扬中市| 灌云县| 河池市| 沈丘县| 德州市| 舟山市| 宝清县| 黔南| 佛坪县| 稻城县| 安义县| 东山县| 睢宁县| 红桥区| 阿坝县| 梁山县| 贡嘎县| 九龙县| 正蓝旗| 开江县| 普兰店市| 绿春县| 崇仁县| 大英县| 邯郸县| 水富县| 大洼县| 登封市| 毕节市| 达孜县| 本溪| 鄂州市| 南充市| 札达县| 乌鲁木齐市| 西峡县| 即墨市| 娄底市|