Ansible AWX Basic Configuration and Use

AWX is an open source web applications, and provides a user interface and the REST API for the ansible task engine. It is an open source version of ansible Tower. ansible AWX allows us to use a web interface to manage Ansible of playbooks, inventoris and scheduling tasks.

Basic environment configuration:

Deployment AWX:
https://blog.51cto.com/10616534/2405212
We will Ansible AWX web interface to complete a simple hello world by running a Ansible playbook.
The following two servers (AWX platform deployment and target servers):

  192.168.100.100   AWX-server
  192.168.100.2   test

AWX simple to use

1) Create a server authentication management objectives

First, let's configure the certificate Ansible AWX for host authentication management of the target node at start and run the task. The default Ansible AWX supports a variety of authentication credentials, including SSH-based authentication, Amazon Web Services, Google Computer Engine , OpenStack, Vault password, Source Control between conventional server and so on.
Such as:
Ansible AWX Basic Configuration and Use
To create a new authentication credentials, internet AWX web in the left menu Credentials, then the right side of the page Why + button to add a Credentials, as shown below:
Ansible AWX Basic Configuration and Use

Credentials fill in the name and description, select Credentials type, select a relatively simple Machine, which allows to manage through SSH authentication server. It supports two authentication methods: password-based and based on secret keys.
Ansible AWX Basic Configuration and Use
We will use the secret key based authentication method, it is necessary to fill in the user name and user system SSH private key: as shown below:
Ansible AWX Basic Configuration and Use
Finally click Save to save the right, success will create a new Machine type Ansible AWX credentials.
Ansible AWX Basic Configuration and Use

2) create Inventories

Inventories defined by the host groups Ansible AWX management. Inventories allows you to create a group for a few servers, and also very convenient to manage different servers and they depend on the environment variables. In order to manage the operation of the server, we have to create a new inventory group and add a server to this group.
Also, click on the menu Inventories ansible AWX the left side, then click the + button on the right, and select Inventory:
Ansible AWX Basic Configuration and Use
as follows: first fill in a name and description, and click Save
Ansible AWX Basic Configuration and Use
and then host Why top of the page (HOSTS) button, and click on the right +, add inventory to the host side, as shown:
Ansible AWX Basic Configuration and Use
as shown below: fill in the host name (hOST nAME), description (the dESCRIPTION), and in VARIABLES, fill in the IP address of the target host "ansible_host: 192.168. 100.2 ", and click save (sAVE).
Ansible AWX Basic Configuration and Use
Then we can see the hosts inventory we just created in the newly added in the bottom of the page, in order to ensure that the host configuration, we can check the host by the ping command, select the check box in front of the host to add and click the button RUN COMMANDS .
Ansible AWX Basic Configuration and Use
Then select ping module (MODILE -> Choose a module - ping), then select Credentials (certification) the way we created in the first step, and then the solution LAUNCH button to the right
Ansible AWX Basic Configuration and Use
and then we will see what the results page , as shown:
Ansible AWX Basic Configuration and Use
At this point, successfully created a new inventory, and add the target host (server) specified.

3) Create a Projects

在于AWX中,Projects的作用相当于对一个Ansible Playbook库的管理,他可以对本地目录或者对类似GIt、Svn(Subversion)及RedHat Insights中的Ansible Playboos进行管理。
创建一个新的Projects,点击左侧的Projects菜单按钮,点击右侧的+,进行创建,如下图:
Ansible AWX Basic Configuration and Use
填写创建Project的名称以及描述(可选),并选择一个SCM TYPE,我们这里选择 Manual类型(选择本地目录),指定项目的基础路径(PROJECT BASE PATH),并在项目的基础路径下选择一个存放playbook的目录(说明:即如果SCM TYPE类型选择Manual,则项目的基础路径将指向本地目录,此时需要在这个目录下根据自己的部署操作需求创建子目录,并将指定的playbook文件放在自己创建的目录中,以供在创建项目(Project是使用)),最后点击右侧的save保存,如图:
Ansible AWX Basic Configuration and Use
Ansible AWX Basic Configuration and Use
注意:如果在创建Project时需要选择SCM类型为Manual,则/var/lib/awx/projects是Ansible playbooks默认的项目目录,如果你部署AWX是采用的是Docker形式部署的,则需要开启project_data_dir选项。例如通过docker-compose安装部署的AWX,则可以修改awx/installer目录下的inventory文件,如下:
Ansible AWX Basic Configuration and Use

4)创建一个任务模板

Task template is actually to run Ansible Playbooks, create a new template need to select the target host (in inventory redefined, select inventory own newly created), authentication (selected in the Credentials in a way that select Credentials own newly created ), and select the project file specified in the playbook.
Click on the left of the Template button on the right +, and select Job template options:
Ansible AWX Basic Configuration and Use
fill in the name and description of the newly created task template, and choose to create ever before INVENTORY, CREDENTIAL and PROJECT, and then save and finally you can go run a template task specific playbooks to be deployed.
Ansible AWX Basic Configuration and Use
hello_world.yml task is a helloword output to the specified file on the target host:

---
- hosts: all
  tasks:
     - name: "helloworld"
       shell: echo "Hello World" `date` by `hostname` > /tmp/hello.log

5) run a template task

We can run the job template to specify Projects corresponding playbooks, and deployed on Invertory specified target host.
Click on the right side of Templates, and then find the specified job Template, and then click on the icon on the right to run the task.
Ansible AWX Basic Configuration and Use
Results are as follows:
Ansible AWX Basic Configuration and Use
Ansible AWX Basic Configuration and Use

Finally, check whether the destination node in accordance with a specified operation to complete playbooks

Ansible AWX Basic Configuration and Use
Explained the success of the implementation of the specified operation on the specified target host.

Guess you like

Origin blog.51cto.com/10616534/2407182
AWX