In a play
All tasks are ran as the become_user
user.
- name: Super awesome play.
become_user: tyler
tasks:
- name: Some task
copy: src=/foo dest=/bar
In a play
All tasks are ran as the become_user
user.
- name: Super awesome play.
become_user: tyler
tasks:
- name: Some task
copy: src=/foo dest=/bar
As a software engineer I require a consistent style in any configuration or code. Static analysis and style checking are very important for project health. These procedures have a place in any project.
With Ansible, parameters can be written as fully expanded YAML dictionaries or as condensed key=value
pairs. It is left up to the user to decide between the styles. Working on playbooks, roles, or tasks that use both styles can be tedious compared to just using expanded YAML dictionaries.
Something that I have recently decided on is to use YAML as YAML with Ansible. I use fully expanded YAML dictionaries everywhere now. My recommendation is that you try it, too.
#!/usr/bin/python | |
""" Ansible Inventory Generated From Netbox | |
Author: Stanley Karunditu <stanley@linuxsimba.com> | |
License: MIT | |
Requirements: | |
* use netbox device roles that result in hyphenated role names. E.g |
--- | |
- name: install and start apache | |
hosts: web | |
become: yes | |
vars: | |
http_port: 80 | |
tasks: | |
- name: httpd package is present | |
yum: | |
name: httpd |
```yaml | |
- name: Provision a compute instance | |
hosts: localhost | |
gather_facts: no | |
become: no | |
vars: | |
os_config_file: "{{ lookup('env', 'OS_CLIENT_CONFIG_FILE') }}" | |
os_auth: | |
project_name: "{{ lookup('env', 'OS_PROJECT') }}" | |
auth_url: "{{ lookup('env', 'OS_AUTH_URL') }}" |