[root@ansible ~]# ssh-copy-id root@httpd #传递公钥
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: “/root/.ssh/id_rsa.pub”
The authenticity of host ‘httpd (192.168.129.133)’ can’t be established.
ECDSA key fingerprint is SHA256:+wH81RHiBmLpbkuk2OWGZxVRziiaNwJ9KAVjGtEM8zs.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed – if you are prompted now it is to install the new keys
root@httpd’s password:
Number of key(s) added: 1
Now try logging into the machine, with: “ssh ‘root@httpd’”
and check to make sure that only the key(s) you wanted were added.
ping
[root@ansible playbook]# ansible all -m ping
192.168.129.135 | SUCCESS => {
“ansible_facts”: {
“discovered_interpreter_python”: “/usr/libexec/platform-python”
},
“changed”: false,
“ping”: “pong”
}
[root@ansible playbook]# tree
.
├── bao.yml
├── install.yml
└── pei.yml
wget https://mirrors.bfsu.edu.cn/apache/apr/apr-1.7.0.tar.gz
wget https://mirrors.bfsu.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
wget https://mirrors.bfsu.edu.cn/apache/httpd/httpd-2.4.48.tar.gz
bao.yml
[root@ansible playbook]# cat bao.yml
- hosts: httpd
tasks:
- name: httpd
get_url:
url: https://mirrors.bfsu.edu.cn/apache/httpd/httpd-2.4.48.tar.gz
dest: /opt
- name: apr
get_url:
url: https://mirrors.bfsu.edu.cn/apache/apr/apr-1.7.0.tar.gz
dest: /opt
- name: apr-util
get_url:
url: https://mirrors.bfsu.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
dest: /opt
空运行
[root@ansible playbook]# ansible-playbook -C bao.yml
PLAY [httpd] ********************************************************************************************************************************************************
TASK [Gathering Facts] **********************************************************************************************************************************************
ok: [192.168.129.135]
TASK [httpd] ********************************************************************************************************************************************************
changed: [192.168.129.135]
TASK [apr] **********************************************************************************************************************************************************
changed: [192.168.129.135]
TASK [apr-util] *****************************************************************************************************************************************************
changed: [192.168.129.135]
PLAY RECAP **********************************************************************************************************************************************************
192.168.129.135 : ok=4 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
[root@ansible playbook]# cat pei.yml
dell: gcc,gcc-c++,perl,perl-devel,expat-devel,pcre-devel,pcre
apr_install: " cd /root/apr-1.7.0/ && ./configure --prefix=/usr/local/apr && make && make install "
apr_util_install: “cd /root/apr-util-1.6.1/ && ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install”
httpd_install: " cd /root/httpd-2.4.48/ && ./configure --prefix=/usr/local/httpd --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util && make && make install "
install.yml文件
[root@ansible playbook]# cat install.yml
- hosts: httpd
vars_files:
- /opt/playbook/pei.yml
tasks:
- name: stop and disabled firewalld
service:
name: firewalld
state: stopped
enabled: no
- name: disabled selinux
lineinfile:
path: /etc/selinux/config
regexp: “^SELINUX=”
line: “SELINUX=disabled”
state: present
- name: install tools
yum:
name: “{{ dell }}”
state: present
- name: apr
unarchive:
src: /opt/apr-1.7.0.tar.gz
dest: /root
copy: no
tags: unarchive
- name: apr-util
unarchive:
src: /opt/apr-util-1.6.1.tar.gz
dest: /root
copy: no
tags: unarchive
- name: httpd
unarchive:
src: /opt/httpd-2.4.48.tar.gz
dest: /root
copy: no
tags: unarchive
- name: del
lineinfile:
dest: /root/apr-17.0/configure
regexp: ‘ R M " RM " RM"cfgfile"’
state: absent
- name: create group
group:
name: apache
system: yes
state: present
- name: create user
user:
name: apache
system: yes
state: present
- name: install apr
shell: " {{ apr_install }}"
- name: intall apr-util
shell: " {{ apr_util_install }}"
- name: install httpd
shell: " {{ httpd_install }} "
- name: start httpd service
shell: " /usr/local/httpd/bin/apachectl start "
验证语法
[root@ansible playbook]# ansible-playbook --syntax-check install.yml
playbook: install.yml
空运行
[root@ansible playbook]# ansible-playbook -C install.yml
PLAY [httpd] ********************************************************************************************************************************************************
TASK [Gathering Facts] **********************************************************************************************************************************************
ok: [192.168.129.135]
TASK [stop and disabled firewalld] **********************************************************************************************************************************
ok: [192.168.129.135]
TASK [disabled selinux] *********************************************************************************************************************************************
ok: [192.168.129.135]
TASK [install tools] ************************************************************************************************************************************************
ok: [192.168.129.135]
TASK [apr] **********************************************************************************************************************************************************
ok: [192.168.129.135]
TASK [apr-util] *****************************************************************************************************************************************************
ok: [192.168.129.135]
TASK [httpd] ********************************************************************************************************************************************************
ok: [192.168.129.135]
TASK [del] **********************************************************************************************************************************************************
ok: [192.168.129.135]
TASK [create group] *************************************************************************************************************************************************
ok: [192.168.129.135]
TASK [create user] **************************************************************************************************************************************************
ok: [192.168.129.135]
TASK [install apr] **************************************************************************************************************************************************
changed: [192.168.129.135]
TASK [intall apr-util] **********************************************************************************************************************************************
changed: [192.168.129.135]
TASK [install httpd] ************************************************************************************************************************************************
changed: [192.168.129.135]
TASK [start httpd service] ******************************************************************************************************************************************
changed: [192.168.129.135]
PLAY RECAP **********************************************************************************************************************************************************
192.168.129.135 : ok=14 changed=4 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
执行playbook文件
[root@ansible playbook]# ansible-playbook install.yml
PLAY [httpd] ********************************************************************************************************************************************************
TASK [Gathering Facts] **********************************************************************************************************************************************
ok: [192.168.129.135]
TASK [stop and disabled firewalld] **********************************************************************************************************************************
ok: [192.168.129.135]
TASK [disabled selinux] *********************************************************************************************************************************************
ok: [192.168.129.135]
TASK [install tools] ************************************************************************************************************************************************
ok: [192.168.129.135]
TASK [apr] **********************************************************************************************************************************************************
ok: [192.168.129.135]
TASK [apr-util] *****************************************************************************************************************************************************
ok: [192.168.129.135]
TASK [httpd] ********************************************************************************************************************************************************
ok: [192.168.129.135]
TASK [del] **********************************************************************************************************************************************************
ok: [192.168.129.135]
TASK [create group] *************************************************************************************************************************************************
ok: [192.168.129.135]
TASK [create user] **************************************************************************************************************************************************
ok: [192.168.129.135]
最后
码字不易,觉得有帮助的可以帮忙点个赞,让更多有需要的人看到
又是一年求职季,在这里,我为各位准备了一套Java程序员精选高频面试笔试真题,来帮助大家攻下BAT的offer,题目范围从初级的Java基础到高级的分布式架构等等一系列的面试题和答案,用于给大家作为参考
以下是部分内容截图
29.135]
TASK [create group] *************************************************************************************************************************************************
ok: [192.168.129.135]
TASK [create user] **************************************************************************************************************************************************
ok: [192.168.129.135]
最后
码字不易,觉得有帮助的可以帮忙点个赞,让更多有需要的人看到
又是一年求职季,在这里,我为各位准备了一套Java程序员精选高频面试笔试真题,来帮助大家攻下BAT的offer,题目范围从初级的Java基础到高级的分布式架构等等一系列的面试题和答案,用于给大家作为参考
以下是部分内容截图
[外链图片转存中…(img-D3EIYaZQ-1721131024428)]