Question 1easymultiple choice
Read the full Ansible explanation →EX294 Manage task execution and roles • Complete Question Bank
Complete EX294 Manage task execution and roles question bank — all 0 questions with answers and detailed explanations.
Refer to the exhibit.
```yaml
---
- hosts: all
tasks:
- name: Create user
ansible.builtin.user:
name: jdoe
state: present
register: user_result
- name: Show user info
ansible.builtin.debug:
var: user_result
```Refer to the exhibit.
```
TASK [Gathering Facts] *********************************************************
ok: [server1.example.com]
TASK [role1 : Install package] *************************************************
fatal: [server1.example.com]: FAILED! => {"changed": false, "msg": "No package matching 'httpd' found available, tried all mirrors", "rc": 126, "results": []}
```Refer to the exhibit.
```yaml
- name: Deploy web server
hosts: webservers
roles:
- common
- nginx
```
And the output of `ansible-playbook site.yml --check` shows:
```
PLAY [Deploy web server] *************************
TASK [common : include_vars] *********************
ok: [web1]
TASK [nginx : install nginx] *********************
fatal: [web1]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'nginx_version' is undefined"}
```Drag steps to the numbered slots on the right, or tap a step then tap a slot.
Drag a concept onto its matching description — or click a concept then click the description.
Background daemon or process
IPC or network socket
Time-based activation
Filesystem mount point
Group of units for synchronization
- hosts: all
tasks:
- name: Import tasks
import_tasks: "{{ item }}.yml"
loop:
- setup
- configureTASK [Start long running process] *************************
changed: [host1]
ASYNC POLL on host1: jid=j1234567890 started, poll=0
TASK [Check on async job] *********************************
ok: [host1] => {
"ansible_job_id": "j1234567890",
"finished": 0,
"started": 1
}dependencies:
- role: common
allow_duplicates: falseRefer to the exhibit.
---
- hosts: webservers
roles:
- role: common
- role: nginx
vars:
http_port: 8080
tasks:
- name: ensure nginx is running
ansible.builtin.service:
name: nginx
state: startedRefer to the exhibit.
TASK [Install packages] ********************************************************
fatal: [db1]: FAILED! => {"changed": false, "msg": "No package matching 'mariadb' found"}
...ignoringRefer to the exhibit.
roles/
└── myrole/
├── defaults/
│ └── main.yml
├── tasks/
│ └── main.yml
├── handlers/
│ └── main.yml
├── templates/
├── files/
├── vars/
│ └── main.yml
├── meta/
│ └── main.yml
└── README.md---
- hosts: dbservers
tasks:
- name: Create postgres user
user:
name: postgres
state: present
become: yes
become_user: postgres
become_method: sudo
Error:
fatal: [server1]: FAILED! => {"msg": "Missing sudo password"}---
- hosts: webservers
vars:
http_port: 80
tasks:
- name: Ensure Apache is running
service:
name: httpd
state: started
- name: Check if port is open
wait_for:
host: "{{ ansible_facts['default_ipv4']['address'] }}"
port: "{{ http_port }}"
state: started
delegate_to: localhost[root@control ansible]# cat roles/apache/tasks/main.yml
---
- name: Install httpd
yum:
name: httpd
state: present
notify: restart httpd
- name: Ensure httpd is running
service:
name: httpd
state: started
enabled: yes
[root@control ansible]# cat roles/apache/handlers/main.yml
---
- name: restart httpd
service:
name: httpd
state: restarted
[root@control ansible]# cat playbook.yml
---
- hosts: all
roles:
- apache
[root@control ansible]# ansible-playbook playbook.yml
...
TASK [apache : Install httpd] *************************************************
changed: [server1.example.com]
TASK [apache : Ensure httpd is running] ***************************************
ok: [server1.example.com]
RUNNING HANDLER [apache : restart httpd] **************************************
changed: [server1.example.com][root@control ansible]# cat ansible.cfg
[defaults]
host_key_checking = False
inventory = ./inventory
roles_path = ./roles
[inventory]
enable_plugins = host_list, script, auto, yaml, ini, toml
[privilege_escalation]
become = True
become_method = sudo
become_user = root
become_ask_pass = False
[root@control ansible]# cat inventory
[webservers]
web1 ansible_host=192.168.1.10 ansible_user=admin
web2 ansible_host=192.168.1.11 ansible_user=admin
[dbservers]
db1 ansible_host=192.168.1.20 ansible_user=admin
[all:vars]
ansible_python_interpreter=/usr/bin/python3
[root@control ansible]# ansible webservers -m ping
web1 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
web2 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}