
On Fri, Jan 22, 2021 at 11:42:23AM +0800, Zhang Yale wrote:
[ideology] 1. This script can test hundreds of the ansible roles in upstream git repo. 2. For testing ansible git repo, those cannot be tested in a unified way, It mainly tests ansible roles git repo, and these roles repo will be more and more.
[why] command "ansible-playbook site.yml" can run in localhost, and only need to create an entry YAML file in which the value of hosts is localhost, for example "site.yml", created in the directory at the same level as the roles directory, which can invoke roles in it. And it dose not need to create a host file in $ansible_path.
site.yml like as follow: ``` site.yml --- - hosts: localhost roles: - role: ansible-role-nginx ``` ansible-role-nginx which is an role in ~/.ansible/roles, can install from galaxy or git clone from github.
Signed-off-by: Zhang Yale <ylzhangah@qq.com> --- tests/ansible_test | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 tests/ansible_test
diff --git a/tests/ansible_test b/tests/ansible_test new file mode 100755 index 00000000..38ef0430 --- /dev/null +++ b/tests/ansible_test @@ -0,0 +1,73 @@ +#!/bin/bash +# - ansible_repo + +. $LKP_SRC/lib/debug.sh + +check_vars() +{ + ansible_host=localhost + + [ -n "$ansible_repo" ] || die "ansible_repo is empty" + benchmark=${ansible_repo##*/} + + ansible_path=/root/.ansible + [ -d "$ansible_path" ] || mkdir -p /root/.ansible +} + +install_ansible() +{ + [[ "$os" == "openeuler" ]] && pip3 install ansible + [[ "$os" == "centos" ]] && yum install -y ansible + [[ "$os" == "debian" ]] && apt-get install -y ansible + + command -v ansible > /dev/null && {
you can use has_cmd LKP_SRC/lib/env.sh
+ ansible localhost -m ping
ansible localhost -m ping && { echo "Ansible is successfully deployed!" }
+ [ $? -eq 0 ] && { + echo "Ansible is successfully deployed!" + } + } +} + +download_ansible_role() +{ + ansible_roles_path=$ansible_path/roles + [ -d $ansible_roles_path ] || mkdir -p $ansible_roles_path + cd $ansible_roles_path + git clone https://github.com/$ansible_repo.git || exit + # git clone git://$GIT_SERVER/$ansible_repo.git || exit
this comment has other meanning?
+ # ansible-galaxy install $username.$rolename
^ this line need not exec?
+ if [ $? -eq 0 ]; then + echo "$benchmark is successfully installed" + else + echo "Please check whether your ansible_repo is correct!" + fi
can use this format cmd || { echo "Please check whether your ansible_repo is correct!" return 1 } echo "$benchmark is successfully installed"
+} + +ansible_playbook_run() +{ + cat <<-EOF > "$ansible_path"/site.yml + - hosts: $ansible_host + roles: + - role: $benchmark + EOF + [ $? -eq 0 ] && { + echo "Playbook has been generated!" + } + + ansible-playbook "$ansible_path"/site.yml ^^
Thanks, Shenwei
+ + if [ $? -eq 0 ]; then + echo "Your playbook is running successfully!" + else + echo "Your playbook failed to run!" && exit 1 +} + +main() +{ + check_vars + install_ansible + download_ansible_role + ansible_playbook_run +} + +main -- 2.23.0