Learn Ansible
上QQ阅读APP看书,第一时间看更新

The ansible-console command

Ansible has its own built-in console. Personally, it is not something I have used much at all. To start the console, we simply need to run one of the following commands:

$ ansible-console -i hosts
$ ansible-console -i hosts london
$ ansible-console -i hosts nyc

The first of the three commands targets all of the hosts, while the next two just target the named groups:

As you can see from the Terminal output, you are asked for an Ansible Vault password. Just enter anything here as we do not have anything protected by Ansible Vault; more on that later in the chapter. Once connected, you can see that I am connected to the london group, in which there are two hosts. From here, you can just type a module name, such as ping:

Or use the raw module, by typing raw uptime:

You can also use the same syntax as we did when running the ansible command to pass key-value pairs, for example, yum name=kpartx state=latest:

To leave the console, simple type exit to return to your regular shell.