Ansible: How to call a playbook from another?

Here you have examples in official documentation. https://docs.ansible.com/ansible/2.4/playbooks_reuse_includes.html I had same error as yours after applying the aproved answer. I resolved problem by creating master playbook like this: — – import_playbook: master-okd.yml – import_playbook: infra-okd.yml – import_playbook: compute-okd.yml

How to store ansible_become_pass in a vault and how to use it?

You need to create some vaulted variable files and then either include them in your playbooks or on the command line. If you change your inventory file to use a variable for the become pass this variable can be vaulted: [my-servers] san-francisco ansible_host=san-francisco ansible_ssh_user=user ansible_become_pass=”{{ sanfrancisco_become_pass }}” san-diego ansible_host=san-diego ansible_ssh_user=user ansible_become_pass=”{{ sandiego_become_pass }}” Then use … Read more

Copy local file if exists, using ansible

A more comprehensive answer: If you want to check the existence of a local file before performing some task, here is the comprehensive snippet: – name: get file stat to be able to perform a check in the following task local_action: stat path=/path/to/file register: file – name: copy file if it exists copy: src=/path/to/file dest=/destination/path when: … Read more

How can I check if a string exists in a file?

It’s a tricky one. the lineinfile module is specifically intended for modifying the content of a file, but you can use it for a validation check as well. – name: find lineinfile: dest: /etc/passwd line: “user” check_mode: yes register: presence failed_when: presence.changed check_mode ensures it never updates the file. register saves the variable as noted. … Read more

How to Make Ansible variable mandatory

As Arbab Nazar mentioned, you can use {{ variable | mandatory }} (see Forcing variables to be defined) inside Ansible task. But I think it looks nicer to add this as first task, it checks is app_name, app_user and app_user_group exist: – name: ‘Check mandatory variables are defined’ assert: that: – app_name is defined – … Read more

Ansible with_items vs loop

Update: The most recent Documentation lists down the differences as below The with_ keywords rely on Lookup Plugins – even items is a lookup. The loop keyword is equivalent to with_list, and is the best choice for simple loops. The loop keyword will not accept a string as input, see Ensuring list input for loop: … Read more

Force fact-gathering on all hosts

Ansible version 2 introduced a clean, official way to do this using delegated facts (see: http://docs.ansible.com/ansible/latest/playbooks_delegation.html#delegated-facts). when: hostvars[item][‘ansible_default_ipv4′] is not defined is a check to ensure you don’t check for facts in a host you already know the facts about — # This play will still work as intended if called with –limit “<host>” or … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)