ansible-facts

Reading multiple values from an env file with ansible and storing them as facts

时间秒杀一切 提交于 2021-02-19 05:30:07
问题 I have the following code which reads values from an environment (.env) file and stores them as facts: - name: Read values from environment shell: "source {{ env_path }}; echo $DB_PASSWORD" register: output args: executable: /bin/bash changed_when: false - name: Store read password set_fact: db_password: "{{ output.stdout }}" when: - db_password is undefined changed_when: false - name: Read values from environment shell: "source {{ env_path }}; echo $DB_USER" register: output args: executable

Reading multiple values from an env file with ansible and storing them as facts

不羁岁月 提交于 2021-02-19 05:29:26
问题 I have the following code which reads values from an environment (.env) file and stores them as facts: - name: Read values from environment shell: "source {{ env_path }}; echo $DB_PASSWORD" register: output args: executable: /bin/bash changed_when: false - name: Store read password set_fact: db_password: "{{ output.stdout }}" when: - db_password is undefined changed_when: false - name: Read values from environment shell: "source {{ env_path }}; echo $DB_USER" register: output args: executable

Ansible, How to modify a variable during a loop?

让人想犯罪 __ 提交于 2021-02-10 19:38:23
问题 I am using Ansible 2.3.0.0 and I have tested in Ansible 2.4.0.0, obtaining the same result. My problem is simple. I have the following list: vars: password_text_to_encrypt: - { line: "{{truststore_pass }}" , result: } - { line: "{{ keystore_pass }}" , result: } - { line: "{{ gp_pass }}" , result: } - { line: "{{ datasource_password }}" , result: } - { line: "{{ server_password }}" , result: } - { line: "{{ sftp_password }}" , result: } - { line: "{{ db_userpassword }}" , result: } roles: -

Use Ansible facts in an Ansible ad-hoc command

女生的网名这么多〃 提交于 2021-01-27 06:06:08
问题 Is it possible to use what would normally be included in ansible_facts in an Ansible adhoc command? For example, I have a file at /tmp/myFile on all of my servers and I'd like to do: ansible all -i [inventory file] -m fetch -a "src=/tmp/myFile dest=myFile-[insert ansible_hostname here]" Without having to make a whole playbook for it. 回答1: No you cannot refer to ansible facts in ansible cli. This is because when you run ansible ... -m fetch you are not getting the facts of the host(s) you are

Use Ansible facts in an Ansible ad-hoc command

偶尔善良 提交于 2021-01-27 06:05:00
问题 Is it possible to use what would normally be included in ansible_facts in an Ansible adhoc command? For example, I have a file at /tmp/myFile on all of my servers and I'd like to do: ansible all -i [inventory file] -m fetch -a "src=/tmp/myFile dest=myFile-[insert ansible_hostname here]" Without having to make a whole playbook for it. 回答1: No you cannot refer to ansible facts in ansible cli. This is because when you run ansible ... -m fetch you are not getting the facts of the host(s) you are

Ansible - set a fact from dynamic variables

空扰寡人 提交于 2021-01-20 13:27:06
问题 I call specific variables file from a fact - name: Load vars - {{ ansible_distribution }} {{ ansible_distribution_major_version }} package list include_vars: file: "{{ ansible_distribution | lower }}-pkglist.yml" # if vars file is not found we continue ignore_errors: yes Variables in that file could have different name, depending of the distribution #package for all debians server prefix_debian: - pkgname - pkgname ... #package for all debian 10 server prefix_10 : - specific major version

Concatenate strings using with_items and assign to a variable in Ansible

房东的猫 提交于 2020-12-06 12:31:06
问题 I need to save two 2 IPs to a variable in a vars_file when launching ec2_instances, which are used later during deployment. This is how I am saving a single server ip: - name: Save server public IP to vars file lineinfile: line="server_public_ip{{':'}} {{ item.public_ip }}" dest="{{ansible_env.HOME}}/dynamic_ips_{{ec2_environment}}" with_items: server.instances #server is registered in previous task The output I have in dynamic_ips file is server_public_ip: xxx.xxx.xx.x Now I have 2 servers