Skip to content

Instantly share code, notes, and snippets.

File name: hostname.yml
location: /u02/ansible/ansible/playbooks
Content of the file:
- hosts: all
- tasks:
- command: hostname
Command:
[ansible@calaces_dev_server2 ansible]$ ansible-playbook playbooks/hostname.yml
@pspravin
pspravin / gist:e4e71f7a30f2e555af327474604a3238
Created April 24, 2017 22:37
Error on ansible -m ping all
[opc@vm04 ansible]$ ansible -m ping all
app02 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname app02: Name or service not known\r\n",
"unreachable": true
}
db01 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname db01: Name or service not known\r\n",
"unreachable": true
@pspravin
pspravin / gist:70f93fceba926d930ebe9a27cf5a6feb
Created April 26, 2017 22:10
Unable to install loadbalancer via playbook
[opc@vm04 ansible]$ ansible-playbook loadbalancer.yml
PLAY [loadbalancer] ************************************************************
TASK [setup] *******************************************************************
ok: [129.146.34.164]
TASK [install nginx] ***********************************************************
fatal: [129.146.34.164]: FAILED! => {"changed": false, "cmd": "apt-get update", "failed": true, "msg": "[Errno 2] No such file or directory", "rc": 2}
to retry, use: --limit @/home/opc/ansible/loadbalancer.retry
---
- hosts: loadbalancer
tasks:
- name: install nginx
apt: name=nginx state=present update_cache=yes
~
~
~
~
~
[opc@vm04 ansible]$ ansible-playbook loadbalancer.yml
PLAY [loadbalancer] ************************************************************
TASK [setup] *******************************************************************
ok: [129.146.34.164]
TASK [install nginx] ***********************************************************
fatal: [129.146.34.164]: FAILED! => {"changed": false, "cmd": "apt-get update", "failed": true, "msg": "[Errno 2] No such file or directory", "rc": 2}
to retry, use: --limit @/home/opc/ansible/loadbalancer.retry
---
- hosts: loadbalancer
become: true
tasks:
- name: install nginx
apt: name=nginx state=present update_cache=yes
[opc@lb01 skel]$ sudo yum repolist
Loaded plugins: langpacks, ulninfo
repo id repo name status
ol7_UEKR4/x86_64 Latest Unbreakable Enterprise Kernel Release 4 324
ol7_addons/x86_64 Oracle Linux 7Server Add ons (x86_64) 222
ol7_latest/x86_64 Oracle Linux 7Server Latest (x86_64) 18,931
ol7_optional_latest/x86_64 Oracle Linux 7Server Optional Latest (x86_64) 13,141
repolist: 32,618
[opc@vm04 ansible]$ ansible-playbook loadbalancer.yml
PLAY [loadbalancer] ************************************************************
TASK [setup] *******************************************************************
ok: [129.146.34.164]
TASK [install nginx] ***********************************************************
fatal: [129.146.34.164]: FAILED! => {"changed": false, "failed": true, "msg": "No package matching 'nginx' found available, installed or updated", "rc": 126, "results": ["No package matching 'nginx' found available, installed or updated"]}
to retry, use: --limit @/home/opc/ansible/loadbalancer.retry
---
- hosts: loadbalancer
become: true
tasks:
- name: install nginx
yum: name=nginx state=present
[opc@vm04 ansible]$ ansible-playbook loadbalancer.yml
PLAY [loadbalancer] ************************************************************
TASK [setup] *******************************************************************
ok: [129.146.34.164]
TASK [install nginx] ***********************************************************
fatal: [129.146.34.164]: FAILED! => {"changed": false, "failed": true, "msg": "No package matching 'nginx' found available, installed or updated", "rc": 126, "results": ["No package matching 'nginx' found available, installed or updated"]}
to retry, use: --limit @/home/opc/ansible/loadbalancer.retry