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

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.

主站蜘蛛池模板: 新竹市| 上高县| 清徐县| 道孚县| 外汇| 定兴县| 明水县| 成安县| 庆阳市| 溆浦县| 汪清县| 青铜峡市| 通州市| 岫岩| 察哈| 宁德市| 剑河县| 吉安市| 凤翔县| 荣成市| 嘉峪关市| 沙洋县| 子长县| 南皮县| 奎屯市| 姜堰市| 天柱县| 德钦县| 高青县| 新龙县| 屏山县| 绿春县| 南开区| 池州市| 华蓥市| 荣昌县| 宣汉县| 延边| 阿瓦提县| 班玛县| 同德县|