install ansible create multiple.yml create multiple named inventory install epel-release python pip pyvmomi module
install ansible
[root@localhost ~]# yum install ansible
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.mirrors.estointernet.in
* extras: centos.mirrors.estointernet.in
* updates: centos.mirrors.estointernet.in
Resolving Dependencies
--> Running transaction check
---> Package ansible.noarch 0:2.4.2.0-2.el7 will be installed
--> Processing Dependency: sshpass for package: ansible-2.4.2.0-2.el7.noarch
--> Processing Dependency: python2-jmespath for package: ansible-2.4.2.0-2.el7.noarch
--> Processing Dependency: python-passlib for package: ansible-2.4.2.0-2.el7.noarch
--> Processing Dependency: python-paramiko for package: ansible-2.4.2.0-2.el7.noarch
--> Processing Dependency: python-jinja2 for package: ansible-2.4.2.0-2.el7.noarch
--> Processing Dependency: python-httplib2 for package: ansible-2.4.2.0-2.el7.noarch
--> Running transaction check
---> Package python-httplib2.noarch 0:0.9.2-1.el7 will be installed
---> Package python-jinja2.noarch 0:2.7.2-4.el7 will be installed
--> Processing Dependency: python-babel >= 0.8 for package: python-jinja2-2.7.2-4.el7.noarch
--> Processing Dependency: python-markupsafe for package: python-jinja2-2.7.2-4.el7.noarch
---> Package python-paramiko.noarch 0:2.1.1-9.el7 will be installed
---> Package python-passlib.noarch 0:1.6.5-2.el7 will be installed
---> Package python2-jmespath.noarch 0:0.9.0-3.el7 will be installed
---> Package sshpass.x86_64 0:1.06-2.el7 will be installed
--> Running transaction check
---> Package python-babel.noarch 0:0.9.6-8.el7 will be installed
---> Package python-markupsafe.x86_64 0:0.11-10.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
ansible noarch 2.4.2.0-2.el7 extras 7.6 M
Installing for dependencies:
python-babel noarch 0.9.6-8.el7 base 1.4 M
python-httplib2 noarch 0.9.2-1.el7 extras 115 k
python-jinja2 noarch 2.7.2-4.el7 base 519 k
python-markupsafe x86_64 0.11-10.el7 base 25 k
python-paramiko noarch 2.1.1-9.el7 base 269 k
python-passlib noarch 1.6.5-2.el7 extras 488 k
python2-jmespath noarch 0.9.0-3.el7 extras 39 k
sshpass x86_64 1.06-2.el7 extras 21 k
Transaction Summary
================================================================================
Install 1 Package (+8 Dependent packages)
Total download size: 10 M
Installed size: 51 M
Is this ok [y/d/N]: y
Downloading packages:
(1/9): python-markupsafe-0.11-10.el7.x86_64.rpm | 25 kB 00:02
(2/9): python-jinja2-2.7.2-4.el7.noarch.rpm | 519 kB 00:02
(3/9): python-babel-0.9.6-8.el7.noarch.rpm | 1.4 MB 00:04
(4/9): python-paramiko-2.1.1-9.el7.noarch.rpm | 269 kB 00:01
(5/9): python-passlib-1.6.5-2.el7.noarch.rpm | 488 kB 00:00
ansible-2.4.2.0-2.el7.noarch.r FAILED
http://centos.excellmedia.net/7.7.1908/extras/x86_64/Packages/ansible-2.4.2.0-2.el7.noarch.rpm: [Errno 12] Timeout on http://centos.excellmedia.net/7.7.1908/extras/x86_64/Packages/ansible-2.4.2.0-2.el7.noarch.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
python-httplib2-0.9.2-1.el7.no FAILED
http://centos.excellmedia.net/7.7.1908/extras/x86_64/Packages/python-httplib2-0.9.2-1.el7.noarch.rpm: [Errno 12] Timeout on http://centos.excellmedia.net/7.7.1908/extras/x86_64/Packages/python-httplib2-0.9.2-1.el7.noarch.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
(6/9): sshpass-1.06-2.el7.x86_64.rpm | 21 kB 00:00
(7/9): python-httplib2-0.9.2-1.el7.noarch.rpm | 115 kB 00:00
(8/9): python2-jmespath-0.9.0-3.el7.noarch.rpm | 39 kB 00:00
(9/9): ansible-2.4.2.0-2.el7.noarch.rpm | 7.6 MB 00:06
--------------------------------------------------------------------------------
Total 243 kB/s | 10 MB 00:43
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : python-httplib2-0.9.2-1.el7.noarch 1/9
Installing : sshpass-1.06-2.el7.x86_64 2/9
Installing : python-babel-0.9.6-8.el7.noarch 3/9
Installing : python-paramiko-2.1.1-9.el7.noarch 4/9
Installing : python2-jmespath-0.9.0-3.el7.noarch 5/9
Installing : python-passlib-1.6.5-2.el7.noarch 6/9
Installing : python-markupsafe-0.11-10.el7.x86_64 7/9
Installing : python-jinja2-2.7.2-4.el7.noarch 8/9
Installing : ansible-2.4.2.0-2.el7.noarch 9/9
Verifying : python-markupsafe-0.11-10.el7.x86_64 1/9
Verifying : python-passlib-1.6.5-2.el7.noarch 2/9
Verifying : python2-jmespath-0.9.0-3.el7.noarch 3/9
Verifying : python-paramiko-2.1.1-9.el7.noarch 4/9
Verifying : python-babel-0.9.6-8.el7.noarch 5/9
Verifying : ansible-2.4.2.0-2.el7.noarch 6/9
Verifying : sshpass-1.06-2.el7.x86_64 7/9
Verifying : python-jinja2-2.7.2-4.el7.noarch 8/9
Verifying : python-httplib2-0.9.2-1.el7.noarch 9/9
Installed:
ansible.noarch 0:2.4.2.0-2.el7
Dependency Installed:
python-babel.noarch 0:0.9.6-8.el7 python-httplib2.noarch 0:0.9.2-1.el7
python-jinja2.noarch 0:2.7.2-4.el7 python-markupsafe.x86_64 0:0.11-10.el7
python-paramiko.noarch 0:2.1.1-9.el7 python-passlib.noarch 0:1.6.5-2.el7
python2-jmespath.noarch 0:0.9.0-3.el7 sshpass.x86_64 0:1.06-2.el7
Complete!
[root@localhost ~]# yum install ansible
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.mirrors.estointernet.in
* extras: centos.mirrors.estointernet.in
* updates: centos.mirrors.estointernet.in
Resolving Dependencies
--> Running transaction check
---> Package ansible.noarch 0:2.4.2.0-2.el7 will be installed
--> Processing Dependency: sshpass for package: ansible-2.4.2.0-2.el7.noarch
--> Processing Dependency: python2-jmespath for package: ansible-2.4.2.0-2.el7.noarch
--> Processing Dependency: python-passlib for package: ansible-2.4.2.0-2.el7.noarch
--> Processing Dependency: python-paramiko for package: ansible-2.4.2.0-2.el7.noarch
--> Processing Dependency: python-jinja2 for package: ansible-2.4.2.0-2.el7.noarch
--> Processing Dependency: python-httplib2 for package: ansible-2.4.2.0-2.el7.noarch
--> Running transaction check
---> Package python-httplib2.noarch 0:0.9.2-1.el7 will be installed
---> Package python-jinja2.noarch 0:2.7.2-4.el7 will be installed
--> Processing Dependency: python-babel >= 0.8 for package: python-jinja2-2.7.2-4.el7.noarch
--> Processing Dependency: python-markupsafe for package: python-jinja2-2.7.2-4.el7.noarch
---> Package python-paramiko.noarch 0:2.1.1-9.el7 will be installed
---> Package python-passlib.noarch 0:1.6.5-2.el7 will be installed
---> Package python2-jmespath.noarch 0:0.9.0-3.el7 will be installed
---> Package sshpass.x86_64 0:1.06-2.el7 will be installed
--> Running transaction check
---> Package python-babel.noarch 0:0.9.6-8.el7 will be installed
---> Package python-markupsafe.x86_64 0:0.11-10.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
ansible noarch 2.4.2.0-2.el7 extras 7.6 M
Installing for dependencies:
python-babel noarch 0.9.6-8.el7 base 1.4 M
python-httplib2 noarch 0.9.2-1.el7 extras 115 k
python-jinja2 noarch 2.7.2-4.el7 base 519 k
python-markupsafe x86_64 0.11-10.el7 base 25 k
python-paramiko noarch 2.1.1-9.el7 base 269 k
python-passlib noarch 1.6.5-2.el7 extras 488 k
python2-jmespath noarch 0.9.0-3.el7 extras 39 k
sshpass x86_64 1.06-2.el7 extras 21 k
Transaction Summary
================================================================================
Install 1 Package (+8 Dependent packages)
Total download size: 10 M
Installed size: 51 M
Is this ok [y/d/N]: y
Downloading packages:
(1/9): python-markupsafe-0.11-10.el7.x86_64.rpm | 25 kB 00:02
(2/9): python-jinja2-2.7.2-4.el7.noarch.rpm | 519 kB 00:02
(3/9): python-babel-0.9.6-8.el7.noarch.rpm | 1.4 MB 00:04
(4/9): python-paramiko-2.1.1-9.el7.noarch.rpm | 269 kB 00:01
(5/9): python-passlib-1.6.5-2.el7.noarch.rpm | 488 kB 00:00
ansible-2.4.2.0-2.el7.noarch.r FAILED
http://centos.excellmedia.net/7.7.1908/extras/x86_64/Packages/ansible-2.4.2.0-2.el7.noarch.rpm: [Errno 12] Timeout on http://centos.excellmedia.net/7.7.1908/extras/x86_64/Packages/ansible-2.4.2.0-2.el7.noarch.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
python-httplib2-0.9.2-1.el7.no FAILED
http://centos.excellmedia.net/7.7.1908/extras/x86_64/Packages/python-httplib2-0.9.2-1.el7.noarch.rpm: [Errno 12] Timeout on http://centos.excellmedia.net/7.7.1908/extras/x86_64/Packages/python-httplib2-0.9.2-1.el7.noarch.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
(6/9): sshpass-1.06-2.el7.x86_64.rpm | 21 kB 00:00
(7/9): python-httplib2-0.9.2-1.el7.noarch.rpm | 115 kB 00:00
(8/9): python2-jmespath-0.9.0-3.el7.noarch.rpm | 39 kB 00:00
(9/9): ansible-2.4.2.0-2.el7.noarch.rpm | 7.6 MB 00:06
--------------------------------------------------------------------------------
Total 243 kB/s | 10 MB 00:43
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : python-httplib2-0.9.2-1.el7.noarch 1/9
Installing : sshpass-1.06-2.el7.x86_64 2/9
Installing : python-babel-0.9.6-8.el7.noarch 3/9
Installing : python-paramiko-2.1.1-9.el7.noarch 4/9
Installing : python2-jmespath-0.9.0-3.el7.noarch 5/9
Installing : python-passlib-1.6.5-2.el7.noarch 6/9
Installing : python-markupsafe-0.11-10.el7.x86_64 7/9
Installing : python-jinja2-2.7.2-4.el7.noarch 8/9
Installing : ansible-2.4.2.0-2.el7.noarch 9/9
Verifying : python-markupsafe-0.11-10.el7.x86_64 1/9
Verifying : python-passlib-1.6.5-2.el7.noarch 2/9
Verifying : python2-jmespath-0.9.0-3.el7.noarch 3/9
Verifying : python-paramiko-2.1.1-9.el7.noarch 4/9
Verifying : python-babel-0.9.6-8.el7.noarch 5/9
Verifying : ansible-2.4.2.0-2.el7.noarch 6/9
Verifying : sshpass-1.06-2.el7.x86_64 7/9
Verifying : python-jinja2-2.7.2-4.el7.noarch 8/9
Verifying : python-httplib2-0.9.2-1.el7.noarch 9/9
Installed:
ansible.noarch 0:2.4.2.0-2.el7
Dependency Installed:
python-babel.noarch 0:0.9.6-8.el7 python-httplib2.noarch 0:0.9.2-1.el7
python-jinja2.noarch 0:2.7.2-4.el7 python-markupsafe.x86_64 0:0.11-10.el7
python-paramiko.noarch 0:2.1.1-9.el7 python-passlib.noarch 0:1.6.5-2.el7
python2-jmespath.noarch 0:0.9.0-3.el7 sshpass.x86_64 0:1.06-2.el7
Complete!
create inventory
[root@localhost ~]# cat multiple
[web-vms]
ans-web[01:05] disk='10' datastore='datastore1' memory='256' cpucount='1' guest_id='rhel6Guest'
[root@localhost ~]#
create playbook
[root@localhost ~]# cat multiple.yml
---
- hosts: all
gather_facts: false
connection: local
vars_prompt:
- name: "vsphere_password"
prompt: "vSphere Password"
- name: "notes"
prompt: "VM notes"
private: no
default: "Deployed with ansible"
tasks:
# get date
- set_fact: creationdate="{{lookup('pipe','date "+%Y/%m/%d %H:%M"')}}"
# Create a VM from a template
- name: create the VM
vmware_guest:
hostname: 192.168.0.103
username: root
password: vmware
validate_certs: no
esxi_hostname: 192.168.0.108
datacenter: dc
folder: /dc/vm
name: '{{ inventory_hostname }}'
state: poweredon
guest_id: rhel6Guest
annotation: "{{ notes }} - {{ creationdate }}"
disk:
- size_gb: 10
type: thin
datastore: datastore1
hardware:
memory_mb: 256
num_cpus: 1
scsi: paravirtual
hostname: '{{ inventory_hostname }}'
template: temper
wait_for_ip_address: True
executing ansible playbook with inventory
root@localhost ~]# ansible-playbook -i multiple multiple.yml
vSphere Password:
VM notes [Deployed with ansible]:
PLAY [all] *********************************************************************
TASK [set_fact] ****************************************************************
ok: [ans-web01]
ok: [ans-web02]
ok: [ans-web04]
ok: [ans-web05]
ok: [ans-web03]
TASK [create the VM] ***********************************************************
fatal: [ans-web04]: FAILED! => {"changed": false, "msg": "pyvmomi module required"}
fatal: [ans-web05]: FAILED! => {"changed": false, "msg": "pyvmomi module required"}
fatal: [ans-web02]: FAILED! => {"changed": false, "msg": "pyvmomi module required"}
fatal: [ans-web03]: FAILED! => {"changed": false, "msg": "pyvmomi module required"}
fatal: [ans-web01]: FAILED! => {"changed": false, "msg": "pyvmomi module required"}
to retry, use: --limit @/root/multiple.retry
PLAY RECAP *********************************************************************
ans-web01 : ok=1 changed=0 unreachable=0 failed=1
ans-web02 : ok=1 changed=0 unreachable=0 failed=1
ans-web03 : ok=1 changed=0 unreachable=0 failed=1
ans-web04 : ok=1 changed=0 unreachable=0 failed=1
ans-web05 : ok=1 changed=0 unreachable=0 failed=1
install epel-release repo
[root@localhost ~]# yum install epel-release
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.mirrors.estointernet.in
* extras: centos.mirrors.estointernet.in
* updates: centos.mirrors.estointernet.in
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
epel-release noarch 7-11 extras 15 k
Transaction Summary
================================================================================
Install 1 Package
Total download size: 15 k
Installed size: 24 k
Is this ok [y/d/N]: y
Downloading packages:
epel-release-7-11.noarch.rpm | 15 kB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : epel-release-7-11.noarch 1/1
Verifying : epel-release-7-11.noarch 1/1
Installed:
epel-release.noarch 0:7-11
Complete!
installing python-pip
root@localhost ~]# yum install python-pip
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 7.1 kB 00:00:00
* base: centos.mirrors.estointernet.in
* epel: mirrors.aliyun.com
* extras: centos.mirrors.estointernet.in
* updates: centos.mirrors.estointernet.in
epel | 5.4 kB 00:00:00
(1/3): epel/x86_64/group_gz | 88 kB 00:00:02
(2/3): epel/x86_64/updateinfo | 1.0 MB 00:00:04
(3/3): epel/x86_64/primary_db | 6.8 MB 00:00:05
Resolving Dependencies
--> Running transaction check
---> Package python2-pip.noarch 0:8.1.2-10.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================================
Installing:
python2-pip noarch 8.1.2-10.el7 epel 1.7 M
Transaction Summary
======================================================================================================================================================
Install 1 Package
Total download size: 1.7 M
Installed size: 7.2 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/epel/packages/python2-pip-8.1.2-10.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY0:00:00 ETA
Public key for python2-pip-8.1.2-10.el7.noarch.rpm is not installed
python2-pip-8.1.2-10.el7.noarch.rpm | 1.7 MB 00:00:04
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Importing GPG key 0x352C64E5:
Userid : "Fedora EPEL (7) <epel@fedoraproject.org>"
Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
Package : epel-release-7-11.noarch (@extras)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : python2-pip-8.1.2-10.el7.noarch 1/1
Verifying : python2-pip-8.1.2-10.el7.noarch 1/1
Installed:
python2-pip.noarch 0:8.1.2-10.el7
Complete!
installing pyvmomi module
[root@localhost ~]# pip install pyvmomi
Collecting pyvmomi
Downloading https://files.pythonhosted.org/packages/eb/87/ebf153a3aafdac7c54c5578b6240d7930a8c0a1a21bdd98d271fd131673c/pyvmomi-6.7.3.tar.gz (576kB)
100% |████████████████████████████████| 583kB 847kB/s
Requirement already satisfied (use --upgrade to upgrade): requests>=2.3.0 in /usr/lib/python2.7/site-packages (from pyvmomi)
Requirement already satisfied (use --upgrade to upgrade): six>=1.7.3 in /usr/lib/python2.7/site-packages (from pyvmomi)
Installing collected packages: pyvmomi
Running setup.py install for pyvmomi ... done
Successfully installed pyvmomi-6.7.3
You are using pip version 8.1.2, however version 19.2.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
upgrading pip
root@localhost ~]# pip install --upgrade pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/30/db/9e38760b32e3e7f40cce46dd5fb107b8c73840df38f0046d8e6514e675a1/pip-19.2.3-py2.py3-none-any.whl (1.4MB)
100% |████████████████████████████████| 1.4MB 430kB/s
Installing collected packages: pip
Found existing installation: pip 8.1.2
Uninstalling pip-8.1.2:
Successfully uninstalled pip-8.1.2
Successfully installed pip-19.2.3
now executing again
ansible playbook with inventory
[root@localhost ~]# ansible-playbook -i multiple multiple.yml
vSphere Password:
VM notes [Deployed with ansible]:
PLAY [all] *******************************************************************************************************************************************
TASK [set_fact] **************************************************************************************************************************************
ok: [ans-web01]
ok: [ans-web02]
ok: [ans-web04]
ok: [ans-web05]
ok: [ans-web03]
TASK [create the VM] *********************************************************************************************************************************
changed: [ans-web05]
changed: [ans-web03]
changed: [ans-web04]
changed: [ans-web01]
changed: [ans-web02]
PLAY RECAP *******************************************************************************************************************************************
ans-web01 : ok=2 changed=1 unreachable=0 failed=0
ans-web02 : ok=2 changed=1 unreachable=0 failed=0
ans-web03 : ok=2 changed=1 unreachable=0 failed=0
ans-web04 : ok=2 changed=1 unreachable=0 failed=0
ans-web05 : ok=2 changed=1 unreachable=0 failed=0
vSphere Password:
VM notes [Deployed with ansible]:
PLAY [all] *******************************************************************************************************************************************
TASK [set_fact] **************************************************************************************************************************************
ok: [ans-web01]
ok: [ans-web02]
ok: [ans-web04]
ok: [ans-web05]
ok: [ans-web03]
TASK [create the VM] *********************************************************************************************************************************
changed: [ans-web05]
changed: [ans-web03]
changed: [ans-web04]
changed: [ans-web01]
changed: [ans-web02]
PLAY RECAP *******************************************************************************************************************************************
ans-web01 : ok=2 changed=1 unreachable=0 failed=0
ans-web02 : ok=2 changed=1 unreachable=0 failed=0
ans-web03 : ok=2 changed=1 unreachable=0 failed=0
ans-web04 : ok=2 changed=1 unreachable=0 failed=0
ans-web05 : ok=2 changed=1 unreachable=0 failed=0
Comments
Post a Comment