ansible

Mapping a list of Debian packages in a specific order of 2nd list with Ansible

吃可爱长大的小学妹 提交于 2020-07-09 19:56:07
问题 I'm trying to map a list of files to a list of filenames. The goal is to install Debian files in specific order (base off the list of names). I can retrieve the list of files with a shell command and register them to a list. The goal is to generate a list of filenames in the order of my predefined name list. Then install them in that order. ms2Num.stdout_lines is the list of files from the shell command: # use List -1 to find the file names for the deb files.| grep - name: Find the needed deb

Ansible: iterate over a list of dictionaries - loop vs. with_items

我与影子孤独终老i 提交于 2020-07-09 05:13:42
问题 I'm getting different results when using loop vs with_items when trying to iterate over a list of dictionaries. I've tried using loop|dict2items (the structure isn't a dictionary, & it tells me as much. heh) and loop with the flatten filter. Here is the list of dictionaries: "msg": [ { "id": "id1", "ip": "ip1", "name": "name1" }, { "id": "id2", "ip": "ip2", "name": "name2" }, { "id": "id3", "ip": "ip3", "name": "name3" }, { "id": "id4", "ip": "ip4", "name": "name4" } ] } Here is the task in

Ansible: iterate over a list of dictionaries - loop vs. with_items

南楼画角 提交于 2020-07-09 05:13:01
问题 I'm getting different results when using loop vs with_items when trying to iterate over a list of dictionaries. I've tried using loop|dict2items (the structure isn't a dictionary, & it tells me as much. heh) and loop with the flatten filter. Here is the list of dictionaries: "msg": [ { "id": "id1", "ip": "ip1", "name": "name1" }, { "id": "id2", "ip": "ip2", "name": "name2" }, { "id": "id3", "ip": "ip3", "name": "name3" }, { "id": "id4", "ip": "ip4", "name": "name4" } ] } Here is the task in

Ansible: iterate over a list of dictionaries - loop vs. with_items

删除回忆录丶 提交于 2020-07-09 05:12:16
问题 I'm getting different results when using loop vs with_items when trying to iterate over a list of dictionaries. I've tried using loop|dict2items (the structure isn't a dictionary, & it tells me as much. heh) and loop with the flatten filter. Here is the list of dictionaries: "msg": [ { "id": "id1", "ip": "ip1", "name": "name1" }, { "id": "id2", "ip": "ip2", "name": "name2" }, { "id": "id3", "ip": "ip3", "name": "name3" }, { "id": "id4", "ip": "ip4", "name": "name4" } ] } Here is the task in

Ansible - Using user input to chose a variable

时间秒杀一切 提交于 2020-07-07 04:35:20
问题 I would like to select a specific variable based on user input in an Ansible playbook. Specifically, I would like to ask for user input on a location of a server, and then execute a specific action based on the input. This is the current ansible playbook: - hosts: all remote_user: root gather_facts: True vars: loc1: "10.13.1.140" loc2: "10.13.1.141" loc3: "10.13.1.142" vars_prompt: - name: location prompt: "Location of server? Input options: loc1/loc2/loc3" private: no tasks: - name: Test

Ansible stops connecting to the host via ssh [closed]

微笑、不失礼 提交于 2020-07-07 03:27:32
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Improve this question Introduction For over a month I've been running the following command: ansible-playbook -vvvvi host_test rhel-tests.yml Which connected via SSH and ran tests on a host successfully without any problems. But as of the last couple days, I've received the following

Ansible stops connecting to the host via ssh [closed]

天大地大妈咪最大 提交于 2020-07-07 03:27:20
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Improve this question Introduction For over a month I've been running the following command: ansible-playbook -vvvvi host_test rhel-tests.yml Which connected via SSH and ran tests on a host successfully without any problems. But as of the last couple days, I've received the following

How to test that a registered variable is not empty?

守給你的承諾、 提交于 2020-07-04 08:28:27
问题 How can I test that stderr is non empty:: - name: Check script shell: . {{ venv_name }}/bin/activate && myscritp.py args: chdir: "{{ home }}" sudo_user: "{{ user }}" register: test_myscript - debug: msg='myscritp is Ok' when: not test_myscript.stderr So if there is no error I could read:: TASK: [deploy | debug msg='critp is Ok] ******* ok: [vagrant] => { "msg": "myscritp is Ok" } In case the stderr is not empty a FATAl error occurs. 回答1: You can check for empty string (when stderr is empty) -

Using vault in playbooks

生来就可爱ヽ(ⅴ<●) 提交于 2020-06-29 03:53:10
问题 Hello I am trying to run the following playbook using the vault, but i can't seem to get it to work. Created an ansible vault file using: ansible-valut create group_vars/routers in there i had the following entries: ansible_ssh_user: admin ansible_ssh_pw: admin auth_pass: admin Then i had the following playbook: --- - hosts:routers gather_facts: true connection: local tasks: - name: show run ios_command: authorize: yes auth_pass: "{{ auth_pass }}" commands: - show run register: config When i

how to extend windows path variable using ansible

邮差的信 提交于 2020-06-27 11:59:16
问题 Using win_environment, it is possible to add/remove environment variables to a windows host. But to modify variables that are already there, win_environment does not seem to be useful as u can't read old value to modify and update a variable. right? 回答1: EDIT: Since Ansible 2.3, the win_path module does all the heavy lifting for you. Just give it a list of items that should be present in the path and it'll make sure they're present and in the relative order you specified. (if you're still