AWX ansible - 2877206/docs GitHub Wiki

https://itxx00.github.io/blog/2017/12/20/centos7-install-ansible-awx/

CentOS7系统安装ansible awx记录

发表信息: December 20, 2017 by itxx00 文章分类: system 13 文章标签: shell 2 system 2 记录awx的安装测试过程以及需要注意的点

关于awx 安装过程 关于awx awx(https://github.com/ansible/awx)是ansible tower的开源版本,作为tower的upstream对外开源, 项目从2013年开始维护,2017年由redhat对外开源,目前维护得比较活跃。由于官方的install guide写得有点杂不是很直观, 导致想要安装个简单的测试环境体验一下功能都要折腾半天,这里提供一个简单版本的安装流程方便快速体验。

安装过程 安装软件包

yum -y install epel-release systemctl disable firewalld systemctl stop firewalld sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config setenforce 0 yum -y install git gettext ansible docker nodejs npm gcc-c++ bzip2 python-docker-py 启动服务

systemctl start docker systemctl enable docker clone awx代码

git clone https://github.com/ansible/awx.git cd awx/installer/

注意修改一下postgres_data_dir到其他目录比如/data/pgdocker

vi inventory ansible-playbook -i inventory install.yml 检查日志

docker logs -f awx_task 以上是安装过程,因为本地环境访问外网要经过代理,这里记录一下配置docker通过代理访问外网的方式,否则pull image会有问题。

mkdir /etc/systemd/system/docker.service.d/ cat > /etc/systemd/system/docker.service.d/http-proxy.conf <<EOF [Service] Environment="HTTP_PROXY=proxy.test.dev:8080" "HTTPS_PROXY=proxy.test.dev:8080" "NO_PROXY=localhost,127.0.0.1,172.1.0.2" EOF

systemctl daemon-reload systemctl restart docker systemctl show --property=Environment docker 参考文档:

[1] http://khmel.org/?p=1245

[2] https://docs.docker.com/engine/admin/systemd/#httphttps-proxy

校验和访问

$ docker logs -f awx_task 上面步骤正常的话,可以看到5个容器

awx_task awx_web memcached:alpine rabbitmq postgres 此时就可以正常访问了

访问地址:http://localhost 默认用户:admin 默认密码:password

docker 本地配置

name: Activate AWX Web Container docker_container: name: awx_web state: started restart_policy: unless-stopped image: "{{ awx_web_docker_actual_image }}" volumes:

  • "{{ project_data_dir }}:/var/lib/awx/projects:rw"

name: Activate AWX Task Container docker_container: name: awx_task state: started restart_policy: unless-stopped image: "{{ awx_task_docker_actual_image }}" volumes:

  • "{{ project_data_dir }}:/var/lib/awx/projects:rw"

https://blog.csdn.net/wanglei_storage/article/details/52853034

设置ssh免密登录

0.所有机器创建用户

useradd ansible

ssh-keygen -t rsa

[root@awx ~]# visudo ansible ALL=(ALL) NOPASSWD: ALL

1./etc/hosts

192.168.252.211 zk1.ga 192.168.252.212 zk2.ga 192.168.252.213 zk3.ga

2.主控生成证书:可使用默认值。

# ssh-keygen

3.Copy公钥到客户机

ssh-copy-id -i id_rsa.pub [email protected] -f

6.测试

ssh zk1.ga

测试

添加凭据

选择机器,获取私钥

点击库存,添加。

ansible_connection: ssh

添加主机

ansible_host: 192.168.252.211

host页面执行命令

ansible cmdb

http://ansible-cmdb.readthedocs.io/en/latest/usage/ Github地址: https://github.com/fboender/ansible-cmdb https://www.jianshu.com/p/19b8d185c770 从facts收集信息,生成主机概述

安装 wget https://github.com/fboender/ansible-cmdb/releases/download/1.17/ansible-cmdb-1.17.tar.gz tar zxf ansible-cmdb-1.17.tar.gz cd ansible-cmdb-1.17 make install 使用 生成所有主机得facts信息

ansible -m setup --tree out/ all 生成web页面

ansible-cmdb out/ > overview.html Paste_Image.png 默认模板采用html_fancy,文件存放在/usr/local/lib/ansible-cmdb/ansiblecmdb/data/tpl/html_fancy.tpl

如果facts用了本地缓存,-f指定缓存目录即可。

ansible-cmdb -f /path/to/facts/dir > overview.html 以资产列表得形式统计出ansible主机信息。 ansible-cmdb -t txt_table --columns name,os,ip,mem,cpus out/

Paste_Image.png 输出csv格式的主机信息

ansible-cmdb -t csv -i hosts out/ Paste_Image.png 输出sql文件,导入数据到mysql或者SQLite

ansible-cmdb -t sql -i hosts out/

ansible inventory

https://github.com/ansible/ansible/tree/devel/contrib/inventory

ansible 命令和模块

复制文件

ansible client.wyp.com -m copy -a "src=/etc/ansible dest=/tmp/ansibletest owner=root group=root mode=0755" ansible testhost -m copy -a "src=/etc/passwd dest=/tmp/123/1.txt"