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

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.

主站蜘蛛池模板: 寿光市| 边坝县| 怀仁县| 中西区| 沙洋县| 聂拉木县| 巍山| 洮南市| 新余市| 石泉县| 永顺县| 云浮市| 堆龙德庆县| 巴楚县| 罗甸县| 兰西县| 建阳市| 伊吾县| 虞城县| 镇安县| 渭南市| 保靖县| 呼伦贝尔市| 通榆县| 肇庆市| 兴文县| 类乌齐县| 桦甸市| 白城市| 岳普湖县| 荥阳市| 赣榆县| 沛县| 武川县| 昆明市| 香港| 揭西县| 明溪县| 纳雍县| 汾西县| 略阳县|