Skip to content

Commit

Permalink
Merge pull request #1007 from t-woerner/FQCN_ansible_builtin
Browse files Browse the repository at this point in the history
Use FQCN for ansible.builtin
  • Loading branch information
rjeffman authored Jan 3, 2023
2 parents a8d44e2 + b175c78 commit ba353a9
Show file tree
Hide file tree
Showing 155 changed files with 502 additions and 502 deletions.
2 changes: 1 addition & 1 deletion playbooks/config/retrieve-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
register: serverconfig

- name: Display current configuration.
debug:
ansible.builtin.debug:
msg: "{{ serverconfig }}"
2 changes: 1 addition & 1 deletion playbooks/dnszone/dnszone-reverse-from-ip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
register: result

- name: Zone name inferred from `name_from_ip`
debug:
ansible.builtin.debug:
msg: "Zone created: {{ result.dnszone.name }}"
2 changes: 1 addition & 1 deletion playbooks/host/ensure_host_with_randompassword.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
register: ipahost

- name: Print generated random password
debug:
ansible.builtin.debug:
var: ipahost.host.randompassword
2 changes: 1 addition & 1 deletion playbooks/host/host-present-with-randompassword.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
register: ipahost

- name: Print generated random password
debug:
ansible.builtin.debug:
var: ipahost.host.randompassword
4 changes: 2 additions & 2 deletions playbooks/host/hosts-present-with-randompasswords.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
register: ipahost

- name: Print generated random password for host01.example.com
debug:
ansible.builtin.debug:
var: ipahost.host["host01.example.com"].randompassword

- name: Print generated random password for host02.example.com
debug:
ansible.builtin.debug:
var: ipahost.host["host02.example.com"].randompassword
2 changes: 1 addition & 1 deletion playbooks/user/ensure_user_with_randompassword.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
register: ipauser

- name: Print generated random password
debug:
ansible.builtin.debug:
var: ipauser.user.randompassword
4 changes: 2 additions & 2 deletions playbooks/user/ensure_users_with_randompasswords.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
register: ipauser

- name: Print generated random password for user1
debug:
ansible.builtin.debug:
var: ipauser.user.user1.randompassword

- name: Print generated random password for user2
debug:
ansible.builtin.debug:
var: ipauser.user.user2.randompassword
2 changes: 1 addition & 1 deletion playbooks/vault/retrive-data-asymmetric-vault.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
register: result
no_log: true
- name: Display retrieved data.
debug:
ansible.builtin.debug:
msg: "Data: {{ result.vault.data }}"
2 changes: 1 addition & 1 deletion playbooks/vault/retrive-data-symmetric-vault.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
register: result
no_log: true
- name: Display retrieved data.
debug:
ansible.builtin.debug:
msg: "Data: {{ result.vault.data }}"
4 changes: 2 additions & 2 deletions playbooks/vault/vault-is-present-with-password-file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

tasks:
- name: Copy file containing password to server.
copy:
ansible.builtin.copy:
src: "{{ playbook_dir }}/password.txt"
dest: "{{ ansible_facts['env'].HOME }}/password.txt"
owner: "{{ ansible_user }}"
Expand All @@ -20,6 +20,6 @@
vault_type: symmetric
vault_password_file: "{{ ansible_facts['env'].HOME }}/password.txt"
- name: Remove file containing password from server.
file:
ansible.builtin.file:
path: "{{ ansible_facts['env'].HOME }}/password.txt"
state: absent
4 changes: 2 additions & 2 deletions playbooks/vault/vault-is-present-with-public-key-file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

tasks:
- name: Copy public key file to server.
copy:
ansible.builtin.copy:
src: "{{ playbook_dir }}/public.pem"
dest: "{{ ansible_facts['env'].HOME }}/public.pem"
owner: "{{ ansible_user }}"
Expand All @@ -25,6 +25,6 @@
vault_type: asymmetric
vault_public_key_file: "{{ ansible_facts['env'].HOME }}/public.pem"
- name: Remove public key file from server.
file:
ansible.builtin.file:
path: "{{ ansible_facts['env'].HOME }}/public.pem"
state: absent
10 changes: 5 additions & 5 deletions roles/ipabackup/tasks/backup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# tasks file for ipabackup

- name: Create backup
shell: >
ansible.builtin.shell: >
ipa-backup
{{ "--gpg" if ipabackup_gpg | bool else "" }}
{{ "--gpg-keyring="+ipabackup_gpg_keyring if ipabackup_gpg_keyring is defined else "" }}
Expand All @@ -15,7 +15,7 @@

- block:
- name: Get ipabackup_item from stderr or stdout output
set_fact:
ansible.builtin.set_fact:
ipabackup_item: "{{ item | regex_search('\n.*/([^\n]+)','\\1') | first }}"
when: item.find("Backed up to "+ipabackup_dir+"/") > 0
with_items:
Expand All @@ -25,15 +25,15 @@
label: ""

- name: Fail on missing ipabackup_item
fail: msg="Failed to get ipabackup_item"
ansible.builtin.fail: msg="Failed to get ipabackup_item"
when: ipabackup_item is not defined

- name: Copy backup to controller
include_tasks: "{{ role_path }}/tasks/copy_backup_from_server.yml"
ansible.builtin.include_tasks: "{{ role_path }}/tasks/copy_backup_from_server.yml"
when: state|default("present") == "present"

- name: Remove backup on server
include_tasks: "{{ role_path }}/tasks/remove_backup_from_server.yml"
ansible.builtin.include_tasks: "{{ role_path }}/tasks/remove_backup_from_server.yml"
when: not ipabackup_keep_on_server

when: ipabackup_to_controller
14 changes: 7 additions & 7 deletions roles/ipabackup/tasks/copy_backup_from_server.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
---
- name: Fail on invalid ipabackup_item
fail: msg="ipabackup_item {{ ipabackup_item }} is not valid"
ansible.builtin.fail: msg="ipabackup_item {{ ipabackup_item }} is not valid"
when: ipabackup_item is not defined or
ipabackup_item | length < 1 or
(ipabackup_item.find("ipa-full-") == -1 and
ipabackup_item.find("ipa-data-") == -1)

- name: Set controller destination directory
set_fact:
ansible.builtin.set_fact:
ipabackup_controller_dir:
"{{ ipabackup_controller_path | default(lookup('env','PWD')) }}/{{
ipabackup_name_prefix | default(ansible_facts['fqdn']) }}_{{
ipabackup_item }}/"

- name: Stat backup on server
stat:
ansible.builtin.stat:
path: "{{ ipabackup_dir }}/{{ ipabackup_item }}"
register: result_backup_stat

- name: Fail on missing backup directory
fail: msg="Unable to find backup {{ ipabackup_item }}"
ansible.builtin.fail: msg="Unable to find backup {{ ipabackup_item }}"
when: result_backup_stat.stat.isdir is not defined

- name: Get backup files to copy for "{{ ipabackup_item }}"
shell:
ansible.builtin.shell:
find . -type f | cut -d"/" -f 2
args:
chdir: "{{ ipabackup_dir }}/{{ ipabackup_item }}"
register: result_find_backup_files

- name: Copy server backup files to controller
fetch:
ansible.builtin.fetch:
flat: yes
src: "{{ ipabackup_dir }}/{{ ipabackup_item }}/{{ item }}"
dest: "{{ ipabackup_controller_dir }}"
with_items:
- "{{ result_find_backup_files.stdout_lines }}"

- name: Fix file modes for backup on controller
file:
ansible.builtin.file:
dest: "{{ ipabackup_controller_dir }}"
mode: u=rwX,go=
recurse: yes
Expand Down
14 changes: 7 additions & 7 deletions roles/ipabackup/tasks/copy_backup_to_server.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
---
- name: Fail on invalid ipabackup_name
fail: msg="ipabackup_name {{ ipabackup_name }} is not valid"
ansible.builtin.fail: msg="ipabackup_name {{ ipabackup_name }} is not valid"
when: ipabackup_name is not defined or
ipabackup_name | length < 1 or
(ipabackup_name.find("ipa-full-") == -1 and
ipabackup_name.find("ipa-data-") == -1)

- name: Set controller source directory
set_fact:
ansible.builtin.set_fact:
ipabackup_controller_dir:
"{{ ipabackup_controller_path | default(lookup('env','PWD')) }}"

- name: Set ipabackup_item
set_fact:
ansible.builtin.set_fact:
ipabackup_item:
"{{ ipabackup_name | regex_search('.*_(ipa-.+)','\\1') | first }}"
when: "'_ipa-' in ipabackup_name"

- name: Set ipabackup_item
set_fact:
ansible.builtin.set_fact:
ipabackup_item: "{{ ipabackup_name }}"
when: "'_ipa-' not in ipabackup_name"

- name: Stat backup to copy
stat:
ansible.builtin.stat:
path: "{{ ipabackup_controller_dir }}/{{ ipabackup_name }}"
register: result_backup_stat
delegate_to: localhost
become: no

- name: Fail on missing backup to copy
fail: msg="Unable to find backup {{ ipabackup_name }}"
ansible.builtin.fail: msg="Unable to find backup {{ ipabackup_name }}"
when: result_backup_stat.stat.isdir is not defined

- name: Copy backup files to server for "{{ ipabackup_item }}"
copy:
ansible.builtin.copy:
src: "{{ ipabackup_controller_dir }}/{{ ipabackup_name }}/"
dest: "{{ ipabackup_dir }}/{{ ipabackup_item }}"
owner: root
Expand Down
2 changes: 1 addition & 1 deletion roles/ipabackup/tasks/get_ipabackup_dir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
register: result_ipabackup_get_backup_dir

- name: Set IPA backup dir
set_fact:
ansible.builtin.set_fact:
ipabackup_dir: "{{ result_ipabackup_get_backup_dir.backup_dir }}"
38 changes: 19 additions & 19 deletions roles/ipabackup/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# tasks file for ipabackup

- name: Check for empty vars
fail: msg="Variable {{ item }} is empty"
ansible.builtin.fail: msg="Variable {{ item }} is empty"
when: "item in vars and not vars[item]"
with_items: "{{ ipabackup_empty_var_checks }}"
vars:
Expand All @@ -18,43 +18,43 @@
- ipabackup_firewalld_zone

- name: Set ipabackup_data if ipabackup_data is not set but ipabackup_online is
set_fact:
ansible.builtin.set_fact:
ipabackup_data: yes
when: ipabackup_online | bool and not ipabackup_data | bool

- name: Fail if ipabackup_from_controller and ipabackup_to_controller are set
fail: msg="ipabackup_from_controller and ipabackup_to_controller are set"
ansible.builtin.fail: msg="ipabackup_from_controller and ipabackup_to_controller are set"
when: ipabackup_from_controller | bool and ipabackup_to_controller | bool

- name: Fail for given ipabackup_name if state is not copied, restored or absent
fail: msg="ipabackup_name is given and state is not copied, restored or absent"
ansible.builtin.fail: msg="ipabackup_name is given and state is not copied, restored or absent"
when: state is not defined or
(state != "copied" and state != "restored" and state != "absent") and
ipabackup_name is defined

- name: Get ipabackup_dir from IPA installation
include_tasks: "{{ role_path }}/tasks/get_ipabackup_dir.yml"
ansible.builtin.include_tasks: "{{ role_path }}/tasks/get_ipabackup_dir.yml"

- name: Backup IPA server
include_tasks: "{{ role_path }}/tasks/backup.yml"
ansible.builtin.include_tasks: "{{ role_path }}/tasks/backup.yml"
when: state|default("present") == "present"

- name: Fail on missing ipabackup_name
fail: msg="ipabackup_name is not set"
ansible.builtin.fail: msg="ipabackup_name is not set"
when: (ipabackup_name is not defined or not ipabackup_name) and
state is defined and
(state == "copied" or state == "restored" or state == "absent")

- block:
- name: Get list of all backups on IPA server
shell:
ansible.builtin.shell:
find . -name "ipa-full-*" -o -name "ipa-data-*" | cut -d"/" -f 2
args:
chdir: "{{ ipabackup_dir }}/"
register: result_backup_find_backup_files

- name: Set ipabackup_names using backup list
set_fact:
ansible.builtin.set_fact:
ipabackup_names: "{{ result_backup_find_backup_files.stdout_lines }}"

when: state is defined and
Expand All @@ -64,28 +64,28 @@

- block:
- name: Fail on ipabackup_name all
fail: msg="ipabackup_name can not be all in this case"
ansible.builtin.fail: msg="ipabackup_name can not be all in this case"
when: ipabackup_name is defined and ipabackup_name == "all"

- name: Set ipabackup_names from ipabackup_name string
set_fact:
ansible.builtin.set_fact:
ipabackup_names: ["{{ ipabackup_name }}"]
when: ipabackup_name | type_debug != "list"

- name: Set ipabackup_names from ipabackup_name list
set_fact:
ansible.builtin.set_fact:
ipabackup_names: "{{ ipabackup_name }}"
when: ipabackup_name | type_debug == "list"
when: ipabackup_names is not defined and ipabackup_name is defined

- name: Set empty ipabackup_names if ipabackup_name is not defined
set_fact:
ansible.builtin.set_fact:
ipabackup_names: []
when: ipabackup_names is not defined and ipabackup_name is not defined

- block:
- name: Copy backup from IPA server
include_tasks: "{{ role_path }}/tasks/copy_backup_from_server.yml"
ansible.builtin.include_tasks: "{{ role_path }}/tasks/copy_backup_from_server.yml"
vars:
ipabackup_item: "{{ main_item | basename }}"
with_items:
Expand All @@ -95,7 +95,7 @@
when: state is defined and state == "copied"

- name: Remove backup from IPA server
include_tasks: "{{ role_path }}/tasks/remove_backup_from_server.yml"
ansible.builtin.include_tasks: "{{ role_path }}/tasks/remove_backup_from_server.yml"
vars:
ipabackup_item: "{{ main_item | basename }}"
with_items:
Expand All @@ -111,18 +111,18 @@
# restore.

- name: Fail to copy or restore more than one backup on the server
fail: msg="Only one backup can be copied to the server or restored"
ansible.builtin.fail: msg="Only one backup can be copied to the server or restored"
when: state is defined and (state == "copied" or state == "restored") and
ipabackup_from_controller | bool and ipabackup_names | length != 1

# Use only first item in ipabackup_names for copy to server and for restore.

- block:
- name: Copy backup to server
include_tasks: "{{ role_path }}/tasks/copy_backup_to_server.yml"
ansible.builtin.include_tasks: "{{ role_path }}/tasks/copy_backup_to_server.yml"

- name: Restore IPA server after copy
include_tasks: "{{ role_path }}/tasks/restore.yml"
ansible.builtin.include_tasks: "{{ role_path }}/tasks/restore.yml"
when: state|default("present") == "restored"

vars:
Expand All @@ -131,7 +131,7 @@
(state|default("present") == "copied" and not ipabackup_to_controller)

- name: Restore IPA server
include_tasks: "{{ role_path }}/tasks/restore.yml"
ansible.builtin.include_tasks: "{{ role_path }}/tasks/restore.yml"
vars:
ipabackup_item: "{{ ipabackup_names[0] | basename }}"
when: not ipabackup_from_controller and
Expand Down
2 changes: 1 addition & 1 deletion roles/ipabackup/tasks/remove_backup_from_server.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: Remove backup "{{ ipabackup_item }}"
file:
ansible.builtin.file:
path: "{{ ipabackup_dir }}/{{ ipabackup_item }}"
state: absent
Loading

0 comments on commit ba353a9

Please sign in to comment.